vegvisir/pkg/config/config.go
Piotr Biernat ea6c90236a
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
Renamed src/ to pkg/
Added cache with base redis support
Added profiling in main.go
2021-07-23 16:10:37 +02:00

62 lines
1.0 KiB
Go

// ___ ____ ___ ___
// \ \ / / | _ | __| \ \ / / || | __ || || _ |
// \ \/ / |___ | |__ \ \/ / || |___ || ||___|
// \ / | _ | _ | \ / || __ | || ||\\
// \/ |___ |___ | \/ || ____| || || \\
//
// Copyright (c) 2021 Piotr Biernat. https://pbiernat.dev. MIT License
// Repo: https://git.pbiernat.dev/golang/vegvisir
package config
import (
"encoding/json"
"io/ioutil"
"os"
)
type Config struct {
Server Server
Backends map[string]Backend
}
type Server struct {
Address string
Port int
}
type Backend struct {
PrefixUrl string
BackendAddress string
Protocol string
Routes []Route
}
type Route struct {
Pattern string
Target string
}
var DefaultRoute = Route{
Pattern: "(.*)",
Target: "",
}
func (c *Config) Load(cPath string) error {
if _, err := os.Stat(cPath); err != nil {
return err
}
data, err := ioutil.ReadFile(cPath)
if err != nil {
return err
}
err = json.Unmarshal(data, &c)
if err != nil {
return err
}
return nil
}