代码拉取完成,页面将自动刷新
package config
import (
"github.com/infinitbyte/framework/core/index"
"github.com/infinitbyte/framework/core/pipeline"
"sync"
)
type UpstreamConfig struct {
Name string `config:"name"`
QueueName string `config:"queue_name"`
MaxQueueDepth int64 `config:"max_queue_depth"`
Enabled bool `config:"enabled"`
Writeable bool `config:"writeable"`
Readable bool `config:"readable"`
Timeout string `config:"timeout"`
Elasticsearch index.ElasticsearchConfig `config:"elasticsearch"`
}
func (v *UpstreamConfig) SafeGetQueueName() string {
queueName := v.QueueName
if queueName == "" {
queueName = v.Name
}
return queueName
}
type ProxyConfig struct {
UIEnabled bool
Upstream []UpstreamConfig `config:"upstream"`
Algorithm string `config:"algorithm"`
PassthroughPatterns []string `config:"pass_through"`
}
const Url pipeline.ParaKey = "url"
const Method pipeline.ParaKey = "method"
const Body pipeline.ParaKey = "body"
const Upstream pipeline.ParaKey = "upstream"
const Response pipeline.ParaKey = "response"
const ResponseSize pipeline.ParaKey = "response_size"
const ResponseStatusCode pipeline.ParaKey = "response_code"
const Message pipeline.ParaKey = "message"
//Bucket
const InactiveUpstream = "inactive_upstream"
var proxyConfig ProxyConfig
var upstreams map[string]UpstreamConfig = map[string]UpstreamConfig{}
var l sync.RWMutex
func GetUpstreamConfig(key string) UpstreamConfig {
l.RLock()
defer l.RUnlock()
v := upstreams[key]
return v
}
func GetUpstreamConfigs() map[string]UpstreamConfig {
return upstreams
}
func UpdateUpstreamWriteableStatus(key string, active bool) {
l.Lock()
defer l.Unlock()
v := upstreams[key]
v.Writeable = active
upstreams[key] = v
}
func UpdateUpstreamReadableStatus(key string, active bool) {
l.Lock()
defer l.Unlock()
v := upstreams[key]
v.Readable = active
upstreams[key] = v
}
func GetProxyConfig() ProxyConfig {
return proxyConfig
}
func SetProxyConfig(cfg ProxyConfig) {
proxyConfig = cfg
SetUpstream(cfg.Upstream)
}
func SetUpstream(ups []UpstreamConfig) {
l.Lock()
defer l.Unlock()
for _, v := range ups {
//default Active is true
v.Writeable = true
v.Readable = true
//TODO get upstream status from DB, override active field
upstreams[v.Name] = v
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。