From 0b7a53f8c5504cffcc9939110789ed4b39224222 Mon Sep 17 00:00:00 2001 From: Kay Date: Mon, 30 Oct 2023 21:23:30 +0800 Subject: [PATCH 1/2] feat: config documents --- config/config.go | 18 +++++++++-- config/config.yaml | 9 +++--- config/config_test.go | 5 +++ doc/config/.keep | 0 doc/config/config.md | 71 +++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 97 insertions(+), 6 deletions(-) delete mode 100644 doc/config/.keep create mode 100644 doc/config/config.md diff --git a/config/config.go b/config/config.go index 0eb46cc..bf9b746 100644 --- a/config/config.go +++ b/config/config.go @@ -25,7 +25,8 @@ type Server struct { } type Log struct { - Path string `yaml:"path"` + WriteToFile bool `yaml:"write_to_file"` + Path string `yaml:"path"` } type User struct { @@ -38,6 +39,18 @@ func (conf *Config) BasicCheck() error { if len(conf.Users) <= 0 { return errors.New("invalid user length") } + + for _, u := range conf.Users { + allCmds := false + for _, c := range u.Cmds { + if c == "*" { + allCmds = true + } + } + if allCmds && len(u.Cmds) > 1 { + return errors.New("can't have all cmds and specific cmd at same time") + } + } return nil } @@ -48,7 +61,8 @@ func DefaultConfig() *Config { Port: "7070", }, Log: Log{ - Path: "ttrace.log", + WriteToFile: true, + Path: "ttrace.log", }, Name: "time_trace", } diff --git a/config/config.yaml b/config/config.yaml index c55b8c7..4dfaf2a 100644 --- a/config/config.yaml +++ b/config/config.yaml @@ -5,6 +5,7 @@ server: port: "7070" log: + write_to_file: true path: ttrace.log users: @@ -18,10 +19,10 @@ users: # - name: root # password: super_secret_password # cmd: -# - * # all commands. +# - '*' # all commands. # - name: developer # password: secret_password # cmd: -# - GET -# - PUSH -# - DEL \ No newline at end of file +# - 'GET' +# - 'PUSH' +# - 'DEL' \ No newline at end of file diff --git a/config/config_test.go b/config/config_test.go index cf8b40b..928dacb 100644 --- a/config/config_test.go +++ b/config/config_test.go @@ -53,4 +53,9 @@ func TestBasicCheck(t *testing.T) { c.Users = []User{} err = c.BasicCheck() assert.Error(t, errors.New("invalid user length"), err) + + c.Users = []User{DefaultConfig().Users[0]} + c.Users[0].Cmds = []string{"*", "GET"} + err = c.BasicCheck() + assert.Error(t, errors.New("can't have all cmds and specific cmd at same time"), err) } diff --git a/doc/config/.keep b/doc/config/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/doc/config/config.md b/doc/config/config.md new file mode 100644 index 0000000..f8c992d --- /dev/null +++ b/doc/config/config.md @@ -0,0 +1,71 @@ +# Config + +In this part of documentation we are going to explain config in ttrace. + +### config file + +In ttrace we have config in `yaml` format, you can see default config example [here](../../config/config.yaml). +Now we explain each part of config one by one. + +#### name + +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). +This is name field in `config.yaml`: + +```yml +name: time_trace +``` + +#### server + +In server part you can config this two: which ip? which port? for listening and serving the TCP server. + +This is how it looks in `config.yaml`: + +```yml +server: + listen: localhost + port: "7070" +``` + +#### log + +This part will help you to config log stuff (levels, saving path and...). + +How it looks in `config.yaml`: + +```yml +log: + write_to_file: true + path: ttrace.log +``` + +#### users + +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). + +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. +Also the `CON` command is open for everyone. + +example: + +```yml +users: +- name: root + password: super_secret_password + cmds: + - '*' + +# Also you can use this for multiple users and limited commands +# users: +# - name: root +# password: super_secret_password +# cmd: +# - '*' # all commands. +# - name: developer +# password: secret_password +# cmd: +# - 'GET' +# - 'PUSH' +# - 'DEL' +``` From 1ef631db7d69ae8c75125432ba91e0f6eab4f7d1 Mon Sep 17 00:00:00 2001 From: Kay Date: Thu, 2 Nov 2023 04:03:45 +0800 Subject: [PATCH 2/2] chore: updating version.go comments --- version.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/version.go b/version.go index 492c196..9dd131b 100644 --- a/version.go +++ b/version.go @@ -6,6 +6,7 @@ import ( "fmt" ) +// These constants follow the semantic versioning 2.0.0 spec (http://semver.org/) type Version struct { Meta string `json:"meta" xml:"meta"` Major uint8 `json:"major" xml:"major"` @@ -16,7 +17,7 @@ type Version struct { var version = Version{ Meta: "beta", Major: 0, - Minor: 1, + Minor: 0, Patch: 0, }