From 35416affe377db12d94e5e4b5fbe09c70bd7c602 Mon Sep 17 00:00:00 2001 From: kenriortega Date: Tue, 6 Jul 2021 17:32:55 -0400 Subject: [PATCH] feat: add cache proxy to setting files --- cmd/cli/proxy.go | 4 ++-- cmd/goproxy.go | 4 +++- goproxy.yaml | 2 ++ internal/infra/config.go | 5 +++++ internal/utils/security.go | 2 ++ 5 files changed, 14 insertions(+), 3 deletions(-) diff --git a/cmd/cli/proxy.go b/cmd/cli/proxy.go index 42bcc32..a3333e7 100644 --- a/cmd/cli/proxy.go +++ b/cmd/cli/proxy.go @@ -13,7 +13,7 @@ import ( services "github.com/kenriortega/goproxy/proxy/services" ) -func Start(generateApiKey bool, endpoints []domain.ProxyEndpoint, host string, port int) { +func Start(generateApiKey bool, endpoints []domain.ProxyEndpoint, host string, port int, engine string) { var proxyRepository domain.ProxyRepository clientBadger := infra.GetBadgerDB(false) @@ -25,7 +25,7 @@ func Start(generateApiKey bool, endpoints []domain.ProxyEndpoint, host string, p if generateApiKey { word := utils.StringWithCharset() apiKey := utils.ApiKeyGenerator(word) - _, err := h.Service.SaveSecretKEY("badger", "secretKey", apiKey) + _, err := h.Service.SaveSecretKEY(engine, "secretKey", apiKey) if err != nil { utils.LogError("genkey: Failed " + err.Error()) } diff --git a/cmd/goproxy.go b/cmd/goproxy.go index 9047341..27ca02e 100755 --- a/cmd/goproxy.go +++ b/cmd/goproxy.go @@ -22,6 +22,7 @@ var ( serverList = "" portLB = 3030 setingFile = "goproxy.yaml" + engine = "badger" ) func init() { @@ -35,6 +36,7 @@ func init() { endpoints = config.ProxyGateway.EnpointsProxy portProxy = config.ProxyGateway.Port host = config.ProxyGateway.Host + engine = config.ProxyCache.Engine generateApiKey = false numcpu := runtime.NumCPU() @@ -53,7 +55,7 @@ func main() { case "lb": cli.StartLB(serverList, portLB) case "proxy": - cli.Start(generateApiKey, endpoints, host, portProxy) + cli.Start(generateApiKey, endpoints, host, portProxy, engine) } } diff --git a/goproxy.yaml b/goproxy.yaml index 782558c..ec10108 100644 --- a/goproxy.yaml +++ b/goproxy.yaml @@ -1,6 +1,8 @@ proxy: host_proxy: 0.0.0.0 port_proxy: 5000 + cache_proxy: + engine: badger # local|badgerDB|redis security: type: jwt # apikey|jwt|none secret_key: 12312312asadsd # apikey jwtkey this value can be replace by genkey command diff --git a/internal/infra/config.go b/internal/infra/config.go index 7afe4c8..64f4d90 100644 --- a/internal/infra/config.go +++ b/internal/infra/config.go @@ -12,9 +12,14 @@ type Config struct { type ProxyGateway struct { Host string `mapstructure:"host_proxy"` Port int `mapstructure:"port_proxy"` + ProxyCache ProxyCache `mapstructure:"cache_proxy"` EnpointsProxy []domain.ProxyEndpoint `mapstructure:"services_proxy"` } +type ProxyCache struct { + Engine string `mapstructure:"cache_proxy"` +} + func LoadConfig(path, name string) (config Config, err error) { viper.AddConfigPath(path) viper.SetConfigName(name) diff --git a/internal/utils/security.go b/internal/utils/security.go index 2a03fd5..39e732a 100644 --- a/internal/utils/security.go +++ b/internal/utils/security.go @@ -43,6 +43,8 @@ func CreateSettingFile(setingFile string) { proxy: host_proxy: 0.0.0.0 port_proxy: 5000 + cache_proxy: + engine: badger # local|badgerDB|redis security: type: jwt # apikey|jwt|none secret_key: key00 # apikey jwtkey this value can be replace by genkey command