使用golang 帮我把这段json写成内置变量 run_type client local_addr 127001 local_port 10900 remote_addr 54dfg4fg5-hkzf2tianziyucom remote_port 36440 password 123 log_level 1 ssl
package main
import ( "encoding/json" )
type Config struct {
RunType string json:"run_type"
LocalAddr string json:"local_addr"
LocalPort int json:"local_port"
RemoteAddr string json:"remote_addr"
RemotePort int json:"remote_port"
Password []string json:"password"
LogLevel int json:"log_level"
SSL struct {
Verify bool json:"verify"
VerifyHostname bool json:"verify_hostname"
Cert string json:"cert"
Cipher string json:"cipher"
CipherTLS13 string json:"cipher_tls13"
SNI string json:"sni"
ALPN []string json:"alpn"
ReuseSession bool json:"reuse_session"
SessionTicket bool json:"session_ticket"
Curves string json:"curves"
} json:"ssl"
Router struct {
Enabled bool json:"enabled"
Bypass []string json:"bypass"
Block []string json:"block"
Proxy []string json:"proxy"
DefaultPolicy string json:"default_policy"
} json:"router"
}
func main() {
data := { "run_type": "client", "local_addr": "127.0.0.1", "local_port": 10900, "remote_addr": "54dfg4fg5-hkzf2.tianziyu.com", "remote_port": 36440, "password": [ "123" ], "log_level": 1, "ssl": { "verify": false, "verify_hostname": false, "cert": "", "cipher": "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES128-SHA:ECDHE-RSA-AES256-SHA:DHE-RSA-AES128-SHA:DHE-RSA-AES256-SHA:AES128-SHA:AES256-SHA:DES-CBC3-SHA", "cipher_tls13": "TLS_AES_128_GCM_SHA256:TLS_CHACHA20_POLY1305_SHA256:TLS_AES_256_GCM_SHA384", "sni": "azure.com", "alpn": [ "h2", "http/1.1" ], "reuse_session": true, "session_ticket": false, "curves": "" }, "router": { "enabled": true, "bypass": [ "geoip:cn", "geoip:private", "full:localhost" ], "block": [ "domain:google.com", "domain:youtube.com", "domain:.com", "domain:.tv" ], "proxy": [ "cidr:128.1.152.0/24" ], "default_policy": "proxy" } }
config := Config{}
err := json.Unmarshal([]byte(data), &config)
if err != nil {
panic(err)
}
// Access the values using config.RunType, config.LocalAddr, etc.
原文地址: https://www.cveoy.top/t/topic/fU8a 著作权归作者所有。请勿转载和采集!