Skip to content

Commit

Permalink
feat: add cache proxy to setting files
Browse files Browse the repository at this point in the history
  • Loading branch information
kenriortega committed Jul 6, 2021
1 parent 5a2286a commit 35416af
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions cmd/cli/proxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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())
}
Expand Down
4 changes: 3 additions & 1 deletion cmd/goproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ var (
serverList = ""
portLB = 3030
setingFile = "goproxy.yaml"
engine = "badger"
)

func init() {
Expand All @@ -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()
Expand All @@ -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)
}

}
2 changes: 2 additions & 0 deletions goproxy.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions internal/infra/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions internal/utils/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 35416af

Please sign in to comment.