Skip to content
This repository was archived by the owner on Sep 7, 2024. It is now read-only.

Commit 50bc6d7

Browse files
authored
feat: config documents (#63)
1 parent 24609c3 commit 50bc6d7

File tree

5 files changed

+97
-6
lines changed

5 files changed

+97
-6
lines changed

config/config.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ type Server struct {
2525
}
2626

2727
type Log struct {
28-
Path string `yaml:"path"`
28+
WriteToFile bool `yaml:"write_to_file"`
29+
Path string `yaml:"path"`
2930
}
3031

3132
type User struct {
@@ -38,6 +39,18 @@ func (conf *Config) BasicCheck() error {
3839
if len(conf.Users) <= 0 {
3940
return errors.New("invalid user length")
4041
}
42+
43+
for _, u := range conf.Users {
44+
allCmds := false
45+
for _, c := range u.Cmds {
46+
if c == "*" {
47+
allCmds = true
48+
}
49+
}
50+
if allCmds && len(u.Cmds) > 1 {
51+
return errors.New("can't have all cmds and specific cmd at same time")
52+
}
53+
}
4154
return nil
4255
}
4356

@@ -48,7 +61,8 @@ func DefaultConfig() *Config {
4861
Port: "7070",
4962
},
5063
Log: Log{
51-
Path: "ttrace.log",
64+
WriteToFile: true,
65+
Path: "ttrace.log",
5266
},
5367
Name: "time_trace",
5468
}

config/config.yaml

+5-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ server:
55
port: "7070"
66

77
log:
8+
write_to_file: true
89
path: ttrace.log
910

1011
users:
@@ -18,10 +19,10 @@ users:
1819
# - name: root
1920
# password: super_secret_password
2021
# cmd:
21-
# - * # all commands.
22+
# - '*' # all commands.
2223
# - name: developer
2324
# password: secret_password
2425
# cmd:
25-
# - GET
26-
# - PUSH
27-
# - DEL
26+
# - 'GET'
27+
# - 'PUSH'
28+
# - 'DEL'

config/config_test.go

+5
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,9 @@ func TestBasicCheck(t *testing.T) {
5353
c.Users = []User{}
5454
err = c.BasicCheck()
5555
assert.Error(t, errors.New("invalid user length"), err)
56+
57+
c.Users = []User{DefaultConfig().Users[0]}
58+
c.Users[0].Cmds = []string{"*", "GET"}
59+
err = c.BasicCheck()
60+
assert.Error(t, errors.New("can't have all cmds and specific cmd at same time"), err)
5661
}

doc/config/.keep

Whitespace-only changes.

doc/config/config.md

+71
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# Config
2+
3+
In this part of documentation we are going to explain config in ttrace.
4+
5+
### config file
6+
7+
In ttrace we have config in `yaml` format, you can see default config example [here](../../config/config.yaml).
8+
Now we explain each part of config one by one.
9+
10+
#### name
11+
12+
First of all we have a name, which is name of instance you are running (you can use it on application layer and get it by commands).
13+
This is name field in `config.yaml`:
14+
15+
```yml
16+
name: time_trace
17+
```
18+
19+
#### server
20+
21+
In server part you can config this two: which ip? which port? for listening and serving the TCP server.
22+
23+
This is how it looks in `config.yaml`:
24+
25+
```yml
26+
server:
27+
listen: localhost
28+
port: "7070"
29+
```
30+
31+
#### log
32+
33+
This part will help you to config log stuff (levels, saving path and...).
34+
35+
How it looks in `config.yaml`:
36+
37+
```yml
38+
log:
39+
write_to_file: true
40+
path: ttrace.log
41+
```
42+
43+
#### users
44+
45+
In users part, you define who can access the database and set permission for them. `name` and `password` field is user pass for connecting (required in `CON` command).
46+
47+
In `cmds` you provide which command in [TQL](../TQL/) they have access to. It can be a list of commands or just a `'*'` which means all.
48+
Also the `CON` command is open for everyone.
49+
50+
example:
51+
52+
```yml
53+
users:
54+
- name: root
55+
password: super_secret_password
56+
cmds:
57+
- '*'
58+
59+
# Also you can use this for multiple users and limited commands
60+
# users:
61+
# - name: root
62+
# password: super_secret_password
63+
# cmd:
64+
# - '*' # all commands.
65+
# - name: developer
66+
# password: secret_password
67+
# cmd:
68+
# - 'GET'
69+
# - 'PUSH'
70+
# - 'DEL'
71+
```

0 commit comments

Comments
 (0)