Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
Clivern committed Jul 26, 2021
1 parent 1895396 commit 05721bc
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
2 changes: 2 additions & 0 deletions cmd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,8 @@ var serverCmd = &cobra.Command{

defer db.Close()

viper.SetDefault("config", config)

e := echo.New()

if viper.GetString("app.mode") == "dev" {
Expand Down
79 changes: 79 additions & 0 deletions core/model/configs.go
Original file line number Diff line number Diff line change
@@ -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
}
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
)

0 comments on commit 05721bc

Please sign in to comment.