From 05721bcba1ac460630874c93aea7fa0cc8769b07 Mon Sep 17 00:00:00 2001 From: Clivern Date: Sun, 17 Jan 2021 21:49:48 +0100 Subject: [PATCH] init --- cmd/server.go | 2 ++ core/model/configs.go | 79 +++++++++++++++++++++++++++++++++++++++++++ go.mod | 1 + 3 files changed, 82 insertions(+) create mode 100644 core/model/configs.go diff --git a/cmd/server.go b/cmd/server.go index 97d5d69..d8c6a4c 100644 --- a/cmd/server.go +++ b/cmd/server.go @@ -137,6 +137,8 @@ var serverCmd = &cobra.Command{ defer db.Close() + viper.SetDefault("config", config) + e := echo.New() if viper.GetString("app.mode") == "dev" { diff --git a/core/model/configs.go b/core/model/configs.go new file mode 100644 index 0000000..03b86c9 --- /dev/null +++ b/core/model/configs.go @@ -0,0 +1,79 @@ +// Copyright 2021 Clivern. All rights reserved. +// Use of this source code is governed by the MIT +// license that can be found in the LICENSE file. + +package model + +import ( + yaml "gopkg.in/yaml.v2" +) + +// Configs type +type Configs struct { + App App `yaml:"app"` +} + +// App type +type App struct { + Endpoints []Endpoints `yaml:"endpoints"` +} + +// Endpoints type +type Endpoints struct { + Name string `yaml:"name"` + Active bool `yaml:"active"` + Proxy Proxy `yaml:"proxy"` +} + +// Proxy type +type Proxy struct { + Upstreams Upstreams `yaml:"upstreams"` + Methods []string `yaml:"methods"` + Authentication Authentication `yaml:"authentication"` + RateLimit RateLimit `yaml:"rate_limit"` + CircuitBreaker CircuitBreaker `yaml:"circuit_breaker"` + ListenPath string `yaml:"listen_path"` +} + +// Authentication type +type Authentication struct { + Status bool `yaml:"status"` + Methods []Methods `yaml:"methods"` +} + +// Methods type +type Methods struct { + ID int `yaml:"id"` +} + +// Upstreams type +type Upstreams struct { + Balancing string `yaml:"balancing"` + Targets []Targets `yaml:"targets"` +} + +// Targets type +type Targets struct { + Target string `yaml:"target"` +} + +// RateLimit type +type RateLimit struct { + Status bool `yaml:"status"` +} + +// CircuitBreaker type +type CircuitBreaker struct { + Status bool `yaml:"status"` +} + +// LoadFromYAML update instance from YAML +func (c *Configs) LoadFromYAML(data []byte) error { + err := yaml.Unmarshal(data, &c) + + if err != nil { + return err + } + + return nil +} diff --git a/go.mod b/go.mod index b9f817d..4bccbb0 100644 --- a/go.mod +++ b/go.mod @@ -20,4 +20,5 @@ require ( github.com/spf13/viper v1.8.1 github.com/stretchr/objx v0.2.0 // indirect github.com/uber/jaeger-client-go v2.29.1+incompatible + gopkg.in/yaml.v2 v2.4.0 )