initial import
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
374f34fd60
commit
a2a241cd78
1
.gitignore
vendored
1
.gitignore
vendored
@ -21,3 +21,4 @@
|
||||
# Go workspace file
|
||||
go.work
|
||||
|
||||
config.yaml
|
||||
|
2
Makefile
Normal file
2
Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
all:
|
||||
go build -o servicechecker ./cmd/servicechecker/*.go
|
23
cmd/servicechecker/main.go
Normal file
23
cmd/servicechecker/main.go
Normal file
@ -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)
|
||||
}
|
||||
}
|
5
go.mod
Normal file
5
go.mod
Normal file
@ -0,0 +1,5 @@
|
||||
module go.unistack.org/servicechecker
|
||||
|
||||
go 1.23.3
|
||||
|
||||
require go.unistack.org/micro/v3 v3.10.100
|
4
go.sum
Normal file
4
go.sum
Normal file
@ -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=
|
29
pkg/config/config.go
Normal file
29
pkg/config/config.go
Normal file
@ -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)
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user