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

Commit

Permalink
feat: read config from config.yaml (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZigBalthazar authored Aug 4, 2023
1 parent 5a705bc commit 4b8a1fa
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 26 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ test:
### Formatting, linting, and vetting
fmt:
gofmt -s -w .
go mod tidy

check:
golangci-lint run \
Expand Down
4 changes: 3 additions & 1 deletion cmd/main.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package main

import (
"os"

"github.com/zurvan-lab/TimeTraceDB/src"
)

func main() {
database := src.CreateDataBase()
database := src.CreateDataBase(os.Args[1])
database.InitSocket()
database.InitUsers()
}
17 changes: 9 additions & 8 deletions config/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@ name: TimeTraceConfig
authorization: false

proc:
- cores: 2
- threads: 4
cores: 2
threads: 4

server:
- listen: localhost
- port: 7070
listen: localhost
port: 7070

log:
- path: ./log
path: ./log

user:
- name: root
- token: super_secret_token
- cmd: []
name: root
token: super_secret_token
cmd:
- all
40 changes: 26 additions & 14 deletions src/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,32 @@ import (
)

type Config struct {
Authorization bool
Proc struct {
Cores, Threads int
}
Listen struct {
IP, Port string
}
Log struct {
Path string
}
User struct {
Name string
Token string
}
Name string `yaml:"name"`
Authorization bool `yaml:"authorization"`
Proc Proc `yaml:"proc"`
Listen Listen `yaml:"server"`
Log Log `yaml:"log"`
FirstUser FirstUser `yaml:"user"`
}

type Proc struct {
Cores int `yaml:"cores"`
Threads int `yaml:"threads"`
}

type Listen struct {
IP string `yaml:"listen"`
Port string `yaml:"port"`
}

type Log struct {
Path string `yaml:"path"`
}

type FirstUser struct {
Name string `yaml:"name"`
Token string `yaml:"token"`
Cmd []string `yaml:"cmd"`
}

func createConfig() *Config {
Expand Down
6 changes: 3 additions & 3 deletions src/database.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ type Database struct {
Users Users
}

func CreateDataBase() *Database {
func CreateDataBase(path string) *Database {
return &Database{
Sets: *NewSets(),
Config: *ReadConfigFile(""),
Config: *ReadConfigFile(path),
}
}

Expand All @@ -31,5 +31,5 @@ func (db *Database) InitUsers() {
users := CreateUsers()
db.Users = *users
cmds := []string{"all"}
users.NewUser(db.Config.User.Name, db.Config.User.Token, cmds)
users.NewUser(db.Config.FirstUser.Name, db.Config.FirstUser.Token, cmds)
}

0 comments on commit 4b8a1fa

Please sign in to comment.