diff --git a/.gitignore b/.gitignore index adf8f72..6db70a3 100644 --- a/.gitignore +++ b/.gitignore @@ -21,3 +21,4 @@ # Go workspace file go.work +config.yaml diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..2e9652a --- /dev/null +++ b/Makefile @@ -0,0 +1,2 @@ +all: + go build -o servicechecker ./cmd/servicechecker/*.go \ No newline at end of file diff --git a/cmd/servicechecker/main.go b/cmd/servicechecker/main.go new file mode 100644 index 0000000..ec171c0 --- /dev/null +++ b/cmd/servicechecker/main.go @@ -0,0 +1,23 @@ +package main + +import ( + "context" + "os" + + "go.unistack.org/micro/v3/logger/slog" + "go.unistack.org/servicechecker/pkg/config" +) + +func main() { + ctx := context.Background() + log := slog.NewLogger() + f, err := os.Open("config.yaml") + if err != nil { + log.Fatal(ctx, "failed to open config", err) + } + defer f.Close() + cfg := &config.Config{} + if err = cfg.Parse(f); err != nil { + log.Fatal(ctx, "failed to open config", err) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..a274244 --- /dev/null +++ b/go.mod @@ -0,0 +1,5 @@ +module go.unistack.org/servicechecker + +go 1.23.3 + +require go.unistack.org/micro/v3 v3.10.100 diff --git a/go.sum b/go.sum new file mode 100644 index 0000000..0f1c4f5 --- /dev/null +++ b/go.sum @@ -0,0 +1,4 @@ +github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I= +github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= +go.unistack.org/micro/v3 v3.10.100 h1:yWOaU0ImCGm5k5MUzlIobJUOr+KLfrR/BoDZvcHyKxM= +go.unistack.org/micro/v3 v3.10.100/go.mod h1:YzMldzHN9Ei+zy5t/Psu7RUWDZwUfrNYiStSQtTz90g= diff --git a/pkg/config/config.go b/pkg/config/config.go new file mode 100644 index 0000000..9fc5ece --- /dev/null +++ b/pkg/config/config.go @@ -0,0 +1,29 @@ +package config + +import "io" + +type Config struct { + Services []*Service `json:"services,omitempty" yaml:"services,omitempty"` +} + +type Service struct { + Name string `json:"name,omitempty" yaml:"name,omitempty"` + Addr string `json:"addr,omitempty" yaml:"addr,omitempty"` + Checks []Check `json:"checks,omitempty" yaml:"checks,omitempty"` +} + +type Check struct { + Name string `json:"name,omitempty" yaml:"name,omitempty"` + Type string `json:"type,omitempty" yaml:"type,omitempty"` + Data string `json:"data,omitempty" yaml:"data,omitempty"` + Timeout string `json:"timeout,omitempty" yaml:"timeout,omitempty"` +} + +func (cfg *Config) Parse(r io.Reader) error { + buf, err := io.ReadAll(r) + if err != nil { + return err + } + + return yaml.Unmarshal(buf, cfg) +}