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

chore: add semantic versioning comment in version.go #65

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}

Expand All @@ -48,7 +61,8 @@ func DefaultConfig() *Config {
Port: "7070",
},
Log: Log{
Path: "ttrace.log",
WriteToFile: true,
Path: "ttrace.log",
},
Name: "time_trace",
}
Expand Down
9 changes: 5 additions & 4 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ server:
port: "7070"

log:
write_to_file: true
path: ttrace.log

users:
Expand All @@ -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
# - 'GET'
# - 'PUSH'
# - 'DEL'
5 changes: 5 additions & 0 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Empty file removed doc/config/.keep
Empty file.
71 changes: 71 additions & 0 deletions doc/config/config.md
Original file line number Diff line number Diff line change
@@ -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'
```
3 changes: 2 additions & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -16,7 +17,7 @@ type Version struct {
var version = Version{
Meta: "beta",
Major: 0,
Minor: 1,
Minor: 0,
Patch: 0,
}

Expand Down