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

Commit

Permalink
refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicola Strappazzon C committed Oct 7, 2023
1 parent 0934b40 commit a5afefb
Show file tree
Hide file tree
Showing 87 changed files with 1,622 additions and 1,695 deletions.
87 changes: 0 additions & 87 deletions command/command.go

This file was deleted.

59 changes: 0 additions & 59 deletions command/daemon/daemon.go

This file was deleted.

16 changes: 0 additions & 16 deletions command/version.go

This file was deleted.

53 changes: 0 additions & 53 deletions common/log/log.go

This file was deleted.

43 changes: 13 additions & 30 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,55 +3,38 @@ package config
import (
"errors"
"fmt"
"io/ioutil"
"os"

"github.com/debeando/zenit/common"
"github.com/debeando/go-common/file"
"github.com/debeando/go-common/net"

"github.com/go-yaml/yaml"
)

var File Config

// Init does any initialization necessary for the module.
func init() {
File = Config{
Path: "/etc/zenit/zenit.yaml",
IPAddress: common.IPAddress(),
}
}
var Instance Config

func (c *Config) Load() error {
source, err := ioutil.ReadFile(c.Path)
if err != nil {
source, err = ioutil.ReadFile("zenit.yaml")
if err != nil {
return errors.New(fmt.Sprintf("Fail to read config file: %s or %s", c.Path, "./zenit.yaml"))
}
}
source := file.ReadExpandEnvAsString(c.Path)

source = []byte(os.ExpandEnv(string(source)))

if err := yaml.Unmarshal(source, &c); err != nil {
return errors.New(fmt.Sprintf("Imposible to parse config file - %s", err))
if err := yaml.Unmarshal([]byte(source), &c); err != nil {
return fmt.Errorf("Imposible to parse config file: %s", err)
}

return nil
return c.SanityCheck()
}

// SanityCheck verify the minimum config settings and set default values to start.
func (c *Config) SanityCheck() string {
func (c *Config) SanityCheck() error {
if c.General.Interval < 3 {
c.General.Interval = 30
c.General.Interval = 10

return "Use positive value, and minimun start from 3 seconds, using default 30 seconds."
return errors.New("Use positive value, and minimun start from 3 seconds, using default 10 seconds.")
}

if len(c.General.Hostname) == 0 {
c.General.Hostname = common.Hostname()
c.General.Hostname = net.Hostname()

return "general.hostname: Custom value is not set, using current."
return errors.New("general.hostname: Custom value is not set, using current.")
}

return ""
return nil
}
4 changes: 2 additions & 2 deletions command/example/config.go → config/example/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package example

//go:generate go run ./generate.go

func GetConfigFile() string {
return ExampleFile
func Load() string {
return File
}
4 changes: 2 additions & 2 deletions command/example/example.go → config/example/example.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package example

const ExampleFile = `---
const File = `---
general:
hostname: localhost
interval: 10 # Seconds
interval: 3 # Seconds
debug: true
aws_region: ${AWS_REGION}
aws_access_key_id: ${AWS_ACCESS_KEY_ID}
Expand Down
4 changes: 2 additions & 2 deletions command/example/generate.go → config/example/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
)

func main() {
in, err := os.Open("../../zenit.yaml")
in, err := os.Open("../../../zenit.yaml")
if err != nil {
return
}
Expand All @@ -21,7 +21,7 @@ func main() {
}
defer out.Close()

out.Write([]byte("package example\n\nconst ExampleFile = `"))
out.Write([]byte("package example\n\nconst File = `"))
io.Copy(out, in)
out.Write([]byte("`\n"))
}
38 changes: 23 additions & 15 deletions config/structure.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,26 +32,33 @@ type Config struct {
}
}
Inputs struct {
AWSDiscover struct {
Enable bool `yaml:"enable"`
Username string `yaml:"username"`
Password string `yaml:"password"`
Filter string `yaml:"filter"`
Plugins struct {
Aurora bool `yaml:"aurora"`
Overflow bool `yaml:"overflow"`
Slave bool `yaml:"slave"`
Status bool `yaml:"status"`
Tables bool `yaml:"tables"`
Variables bool `yaml:"variables"`
AWS struct {
Discover struct {
Enable bool `yaml:"enable"`
Username string `yaml:"username"`
Password string `yaml:"password"`
Filter string `yaml:"filter"`
Plugins struct {
MySQL struct {
Enable bool `yaml:"enable"`
Aurora bool `yaml:"aurora"`
Overflow bool `yaml:"overflow"`
Slave bool `yaml:"slave"`
Status bool `yaml:"status"`
Tables bool `yaml:"tables"`
Variables bool `yaml:"variables"`
}
}
}
CloudWatch struct {
Enable bool `yaml:"enable"`
}
}
AWSCloudWatch struct {
Enable bool `yaml:"enable"`
}
MySQL []struct {
Engine string
Hostname string `yaml:"hostname"`
DSN string `yaml:"dsn"`
Enable bool `yaml:"enable"`
Aurora bool `yaml:"aurora"`
Overflow bool `yaml:"overflow"`
Slave bool `yaml:"slave"`
Expand All @@ -62,6 +69,7 @@ type Config struct {
ProxySQL []struct {
Hostname string `yaml:"hostname"`
DSN string `yaml:"dsn"`
Enable bool `yaml:"enable"`
Commands bool `yaml:"commands"`
Errors bool `yaml:"errors"`
Global bool `yaml:"global"`
Expand Down
4 changes: 2 additions & 2 deletions docker/clickhouse/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
FROM ubuntu:18.04

# File Author / Maintainer
MAINTAINER Swapbyt3s
LABEL vendor="Swapbyt3s" \
MAINTAINER DeBeAndo
LABEL vendor="DeBeAndo" \
description="ClickHouse 18.16.1 on Ubuntu 18.04" \
version="18.16.1"

Expand Down
Loading

0 comments on commit a5afefb

Please sign in to comment.