How to use loadJSON method of config Package

Best Selenoid code snippet using config.loadJSON

expand_test.go

Source:expand_test.go Github

copy

Full Screen

1/*2Copyright (c) Jean-François PHILIPPE 2017-20183Package goconfig read config files.4*/5package goconfig6import (7 "encoding/json"8 "io/ioutil"9 "strings"10 "testing"11)12// Check GetString.13func TestExpand0(t *testing.T) {14 builder := NewBuilder("Ctx_", nil)15 str := "{ \"nope\": true, \"key\":\"value\", \"subst\": \"${key}\"}"16 config, err := builder.LoadJSON(strings.NewReader(str))17 if nil != err {18 t.Error("LoadJSON Failed", err)19 }20 // Search a key as string21 str, serr := config.GetString("key")22 if nil != serr {23 t.Error("Key 'key' not found", serr)24 }25 if "value" != str {26 t.Error("Wrong value found :", str)27 }28 // Search a Bool key as String29 str, serr = config.GetString("nope")30 if nil != serr {31 t.Error("Key 'nope' not found", serr)32 }33 if "true" != str {34 t.Error("Wrong value found :", str)35 }36 str, serr = config.GetString("subst")37 if "value" != str {38 t.Error("Key 'subst' not expanded, found", str)39 }40 // Existing value with a default value41 str, serr = config.GetString("subst", "deflt")42 if "value" != str {43 t.Error("Wrong value found :", str)44 }45}46// Check GetString. for nested string47func TestExpand1(t *testing.T) {48 builder := NewBuilder("Ctx_", nil)49 str := "{ \"nope\": true, \"key\":\"value\", \"sub\": { \"key\":\"${nope}\" }}"50 config, err := builder.LoadJSON(strings.NewReader(str))51 if nil != err {52 t.Error("LoadJSON Failed", err)53 }54 // Search a key as string55 str, serr := config.GetString("sub.key")56 if nil != serr {57 t.Error("Key 'sub.key' not found", serr)58 }59 if "true" != str {60 t.Error("Wrong value found :", str)61 }62 // Existing value with a default value63 str, serr = config.GetString("sub.nope.key", "deflt")64 if "deflt" != str {65 t.Error("Wrong value found :", str)66 }67}68// Check expand, with space in key69func TestExpand2(t *testing.T) {70 builder := NewBuilder("Ctx_", nil)71 str := "{ \"nope\": true, \"key\":\"value\", \"sub\": { \"key\":\"${ nope}\" }}"72 config, err := builder.LoadJSON(strings.NewReader(str))73 if nil != err {74 t.Error("LoadJSON Failed", err)75 }76 // Search a key as string77 str, serr := config.GetString("sub.key")78 if nil != serr {79 t.Error("Key 'sub.key' not found", serr)80 }81 if "true" != str {82 t.Error("Wrong value found :", str)83 }84}85// Check expand, with space in key86func TestExpand3(t *testing.T) {87 builder := NewBuilder("Ctx_", nil)88 str := "{ \"nope\": true, \"key\":\"value\", \"sub\": { \"key\":\"${ nope }\" }}"89 config, err := builder.LoadJSON(strings.NewReader(str))90 if nil != err {91 t.Error("LoadJSON Failed", err)92 }93 // Search a key as string94 str, serr := config.GetString("sub.key")95 if nil != serr {96 t.Error("Key 'sub.key' not found", serr)97 }98 if "true" != str {99 t.Error("Wrong value found :", str)100 }101}102// Check expand, with missing subst103func TestExpand4(t *testing.T) {104 builder := NewBuilder("Ctx_", nil)105 str := "{ \"nope\": true, \"key\":\"value\", \"sub\": { \"key\":\"${ none }\" }}"106 config, err := builder.LoadJSON(strings.NewReader(str))107 if nil != err {108 t.Error("LoadJSON Failed", err)109 }110 // Search a key as string111 str, serr := config.GetString("sub.key")112 if nil == serr {113 t.Error("No error for missing subst")114 }115 if "${ none }" != str {116 t.Error("Wrong value found :", str)117 }118}119// Check expand, with subst in defaults120func TestExpand5(t *testing.T) {121 builder := NewBuilder("Ctx_", nil)122 builder.AddDefault("none", "--")123 str := "{ \"nope\": true, \"key\":\"value\", \"sub\": { \"key\":\"${ none }\" }}"124 config, err := builder.LoadJSON(strings.NewReader(str))125 if nil != err {126 t.Error("LoadJSON Failed", err)127 }128 // Search a key as string129 str, serr := config.GetString("sub.key")130 if nil != serr {131 t.Error("Error found for value in defaults", serr)132 }133 if "--" != str {134 t.Error("Wrong value found :", str)135 }136}137// Check expand, with doted key in defaults138func TestExpand6(t *testing.T) {139 builder := NewBuilder("Ctx_", nil)140 builder.AddDefault("none", "--")141 builder.AddDefault("test.none", "-**-")142 str := "{ \"nope\": true, \"key\":\"value\", \"sub\": { \"key\":\"${ test.none }\" }}"143 config, err := builder.LoadJSON(strings.NewReader(str))144 if nil != err {145 t.Error("LoadJSON Failed", err)146 }147 // Search a key as string148 str, serr := config.GetString("sub.key")149 if nil != serr {150 t.Error("Error found for value in defaults", serr)151 }152 if "-**-" != str {153 t.Error("Wrong value found :", str)154 }155}156// Check expand, with doted key, full name is prioritary157// if full name is not found try "last" name (last part of dot)158func TestExpand7(t *testing.T) {159 builder := NewBuilder("Ctx_", nil)160 builder.AddDefault("test.none", "--")161 builder.AddDefault("nope.none", "-**-")162 str := "{ \"nope\": true, \"key\":\"value\", \"sub\": { \"key\":\"${ test.none }\" }}"163 config, err := builder.LoadJSON(strings.NewReader(str))164 if nil != err {165 t.Error("LoadJSON Failed", err)166 }167 // Search a key as string168 str, serr := config.GetString("sub.key")169 if nil != serr {170 t.Error("Error found", err)171 }172 if "--" != str {173 t.Error("Wrong value found :", str)174 }175}176// Check recursive expand, with doted key177func TestExpand8(t *testing.T) {178 builder := NewBuilder("Ctx_", nil)179 builder.AddDefault("test.none", "${key}")180 builder.AddDefault("nope.none", "-**-")181 str := "{ \"nope\": true, \"key\":\"value\", \"sub\": { \"key\":\"${ test.none }\" }}"182 config, err := builder.LoadJSON(strings.NewReader(str))183 if nil != err {184 t.Error("LoadJSON Failed", err)185 }186 // Search a key as string187 str, serr := config.GetString("sub.key")188 if nil != serr {189 t.Error("Error found", err)190 }191 if "value" != str {192 t.Error("Wrong value found :", str)193 }194}195// Check recursive expand, with doted key196func TestExpand9(t *testing.T) {197 builder := NewBuilder("Ctx_", nil)198 builder.AddDefault("idx", "1")199 builder.AddDefault("nope.none", "-**-")200 str := "{ \"nope\": true, \"key1\":\"value\", \"sub\": { \"key\":\"${ key${idx} }\" }}"201 config, err := builder.LoadJSON(strings.NewReader(str))202 if nil != err {203 t.Error("LoadJSON Failed", err)204 }205 // Search a key as string206 str, serr := config.GetString("sub.key")207 if nil != serr {208 t.Error("Error found", err)209 }210 if "value" != str {211 t.Error("Wrong value found :", str)212 }213}214// Check recursive expand, with doted key215func TestExpand10(t *testing.T) {216 builder := NewBuilder("Ctx_", nil)217 builder.AddDefault("idx", "key")218 builder.AddDefault("nope.none", "-**-")219 str := "{ \"nope\": true, \"key\":\"value\", \"sub\": { \"key\":\"${ ${idx} }\" }}"220 config, err := builder.LoadJSON(strings.NewReader(str))221 if nil != err {222 t.Error("LoadJSON Failed", err)223 }224 // Search a key as string225 str, serr := config.GetString("sub.key")226 if nil != serr {227 t.Error("Error found", err)228 }229 if "value" != str {230 t.Error("Wrong value found :", str)231 }232}233// Check recursive expand, with doted key234func TestExpand11(t *testing.T) {235 builder := NewBuilder("Ctx_", nil)236 builder.AddDefault("env", "dev")237 builder.AddDefault("nope.none", "-**-")238 str := "{ \"dev\": {\"db\": {\"pwd\": \"azerty\"}}, \"int\":{\"db\":{\"pwd\":\"qwerty\"}}, \"database\": { \"pwd\":\"${ ${env}.db.pwd }\" }}"239 config, err := builder.LoadJSON(strings.NewReader(str))240 if nil != err {241 t.Error("LoadJSON Failed", err)242 }243 // Search a key as string244 str, serr := config.GetString("database.pwd")245 if nil != serr {246 t.Error("Error found", err)247 }248 if "azerty" != str {249 t.Error("Wrong value found :", str)250 }251}252// Check recursive expand, with doted key253func TestExpand12(t *testing.T) {254 builder := NewBuilder("Ctx_", nil)255 builder.AddDefault("test.none", "${key}")256 builder.AddDefault("nope.none", "-**-")257 str := "{ \"nope\": true, \"key\":\"value\", \"sub\": { \"key\":\"${ test.none \" }}"258 config, err := builder.LoadJSON(strings.NewReader(str))259 if nil != err {260 t.Error("LoadJSON Failed", err)261 }262 // Search a key as string263 str, serr := config.GetString("sub.key")264 if nil != serr {265 t.Error("Error found", err)266 }267 if "${ test.none " != str {268 t.Error("Wrong value found :", str)269 }270}271// Check recursive expand, With Max recursion to 0272func TestExpand13(t *testing.T) {273 builder := NewBuilder("Ctx_", nil)274 builder.SetMaxRecursion(0)275 builder.AddDefault("test.none", "${key}")276 builder.AddDefault("nope.none", "-**-")277 str := "{ \"nope\": true, \"key\":\"value\", \"sub\": { \"key\":\"${ test.none }\" }}"278 config, err := builder.LoadJSON(strings.NewReader(str))279 if nil != err {280 t.Error("LoadJSON Failed", err)281 }282 // Search a key as string283 str, serr := config.GetString("sub.key")284 if nil != serr {285 t.Error("Error found", err)286 }287 // With max recursion to 0 , should return the value288 if "${ test.none }" != str {289 t.Error("Wrong value found :", str)290 }291}292// Check recursive expand, with dmex recursion to 1293func TestExpand14(t *testing.T) {294 builder := NewBuilder("Ctx_", nil)295 builder.SetMaxRecursion(1)296 builder.AddDefault("env", "dev")297 builder.AddDefault("nope.none", "-**-")298 str := "{ \"dev\": {\"db\": {\"pwd\": \"azerty\"}}, \"int\":{\"db\":{\"pwd\":\"qwerty\"}}, \"database\": { \"pwd\":\"${ ${env}.db.pwd }\" }}"299 config, err := builder.LoadJSON(strings.NewReader(str))300 if nil != err {301 t.Error("LoadJSON Failed", err)302 }303 // Search a key as string304 str, serr := config.GetString("database.pwd")305 if nil == serr {306 t.Error("Error should be found")307 }308 // Max recursion reached , should return the value !309 if "${ ${env}.db.pwd }" != str {310 t.Error("Wrong value found :", str)311 }312}313// Check recursive expand, with dmex recursion to 1314func TestExpand15(t *testing.T) {315 builder := NewBuilder("Ctx_", nil)316 builder.SetMaxRecursion(5)317 builder.AddDefault("env", "dev")318 builder.AddDefault("nope.none", "-**-")319 str := "{ \"dev\": {\"db\": {\"pwd\": \"a ${int.db.pwd}\"}}, \"int\":{\"db\":{\"pwd\":\"b ${ ${env}.db.pwd}\"}}, \"database\": { \"pwd\":\"${ ${env}.db.pwd }\" }}"320 config, err := builder.LoadJSON(strings.NewReader(str))321 if nil != err {322 t.Error("LoadJSON Failed", err)323 }324 // Search a key as string325 str, serr := config.GetString("database.pwd")326 if nil == serr {327 t.Error("Error should be found")328 }329 // Max recursion reached , should return the value !330 if "${ ${env}.db.pwd }" != str {331 t.Error("Wrong value found :", str)332 }333}334// Check GetFloat335func TestTranslate16(t *testing.T) {336 str := "{ \"string2\": \"${key}\", \"key\":\"value\", \"sub\": { \"key\":\"value2\" }}"337 builder := NewBuilder("Ctx_", nil)338 builder.SetMaxRecursion(5)339 builder.AddDefault("env", "dev")340 builder.AddDefault("nope.none", "-**-")341 _, err := builder.LoadJSON(strings.NewReader(str))342 if nil != err {343 t.Error("LoadJSON Failed", err)344 }345 jsonBytes, err := ioutil.ReadAll(strings.NewReader(str))346 if err != nil {347 t.Error("ReadAll failed", err)348 }349 var obj map[string]interface{}350 if err := json.Unmarshal(jsonBytes, &obj); err != nil {351 t.Error("Unmarshall failed", err)352 }353 if nil != err {354 t.Error("LoadJSON Failed", err)355 }356 config := builder.conf357 str, err = config.GetString("string2")358 if nil != err {359 t.Error("GetString Failed", err)360 }361 if "value" != str {362 t.Error("Wrong Value returned, expecting value :", str)363 }364 m := make(map[string]interface{})365 m["key0"] = "test"366 m["key1"] = "${nope}"367 m2 := make(map[string]interface{})368 m2["sub2"] = m369 m2["root"] = 12370 m2["string"] = "${key}"371 m2["array"] = []string{"${sub.key}", "array"}372 m3 := config.Translate(m2)373 if nil == m3 {374 t.Error("Translate should not have returned nil")375 }376 switch tsrc := m3.(type) {377 case map[string]interface{}:378 val := tsrc["string"]379 if nil == val {380 t.Error("m3[string] should not be nil")381 }382 switch tsrc2 := val.(type) {383 case string:384 if "value" != tsrc2 {385 t.Error("Wrong value found :", val)386 }387 default:388 t.Error("tsrc[string] should be a string")389 }390 // Test for array391 val = tsrc["array"]392 if nil == val {393 t.Error("m3[array] should not be nil")394 }395 switch tsrc2 := val.(type) {396 case []string:397 if "value2" != tsrc2[0] {398 t.Error("Wrong value found :", val)399 }400 default:401 t.Error("tsrc[string] should be a string")402 }403 default:404 t.Error("m3 should be a map")405 }406}407// vi:set fileencoding=utf-8 tabstop=4 ai...

Full Screen

Full Screen

config_test.go

Source:config_test.go Github

copy

Full Screen

1package rest2import (3 "encoding/json"4 "testing"5 "time"6 crypto "github.com/libp2p/go-libp2p-crypto"7 peer "github.com/libp2p/go-libp2p-peer"8 ma "github.com/multiformats/go-multiaddr"9)10var cfgJSON = []byte(`11{12 "listen_multiaddress": "/ip4/127.0.0.1/tcp/9094",13 "ssl_cert_file": "test/server.crt",14 "ssl_key_file": "test/server.key",15 "read_timeout": "30s",16 "read_header_timeout": "5s",17 "write_timeout": "1m0s",18 "idle_timeout": "2m0s",19 "basic_auth_credentials": null20}21`)22func TestLoadJSON(t *testing.T) {23 cfg := &Config{}24 err := cfg.LoadJSON(cfgJSON)25 if err != nil {26 t.Fatal(err)27 }28 if cfg.ReadTimeout != 30*time.Second ||29 cfg.WriteTimeout != time.Minute ||30 cfg.ReadHeaderTimeout != 5*time.Second ||31 cfg.IdleTimeout != 2*time.Minute {32 t.Error("error parsing timeouts")33 }34 j := &jsonConfig{}35 json.Unmarshal(cfgJSON, j)36 j.HTTPListenMultiaddress = "abc"37 tst, _ := json.Marshal(j)38 err = cfg.LoadJSON(tst)39 if err == nil {40 t.Error("expected error decoding listen multiaddress")41 }42 j = &jsonConfig{}43 json.Unmarshal(cfgJSON, j)44 j.ReadTimeout = "-1"45 tst, _ = json.Marshal(j)46 err = cfg.LoadJSON(tst)47 if err == nil {48 t.Error("expected error in read_timeout")49 }50 j = &jsonConfig{}51 json.Unmarshal(cfgJSON, j)52 j.BasicAuthCreds = make(map[string]string)53 tst, _ = json.Marshal(j)54 err = cfg.LoadJSON(tst)55 if err == nil {56 t.Error("expected error with empty basic auth map")57 }58 j = &jsonConfig{}59 json.Unmarshal(cfgJSON, j)60 j.SSLCertFile = "abc"61 tst, _ = json.Marshal(j)62 err = cfg.LoadJSON(tst)63 if err == nil {64 t.Error("expected error with TLS configuration")65 }66 j = &jsonConfig{}67 json.Unmarshal(cfgJSON, j)68 j.ID = "abc"69 tst, _ = json.Marshal(j)70 err = cfg.LoadJSON(tst)71 if err == nil {72 t.Error("expected error with ID")73 }74 j = &jsonConfig{}75 json.Unmarshal(cfgJSON, j)76 j.Libp2pListenMultiaddress = "abc"77 tst, _ = json.Marshal(j)78 err = cfg.LoadJSON(tst)79 if err == nil {80 t.Error("expected error with libp2p address")81 }82 j = &jsonConfig{}83 json.Unmarshal(cfgJSON, j)84 j.PrivateKey = "abc"85 tst, _ = json.Marshal(j)86 err = cfg.LoadJSON(tst)87 if err == nil {88 t.Error("expected error with private key")89 }90}91func TestLibp2pConfig(t *testing.T) {92 cfg := &Config{}93 err := cfg.Default()94 if err != nil {95 t.Fatal(err)96 }97 priv, pub, err := crypto.GenerateKeyPair(crypto.RSA, 2048)98 if err != nil {99 t.Fatal(err)100 }101 pid, err := peer.IDFromPublicKey(pub)102 if err != nil {103 t.Fatal(err)104 }105 cfg.ID = pid106 cfg.PrivateKey = priv107 addr, _ := ma.NewMultiaddr("/ip4/127.0.0.1/tcp/0")108 cfg.Libp2pListenAddr = addr109 err = cfg.Validate()110 if err != nil {111 t.Error(err)112 }113 cfgJSON, err := cfg.ToJSON()114 if err != nil {115 t.Fatal(err)116 }117 err = cfg.LoadJSON(cfgJSON)118 if err != nil {119 t.Fatal(err)120 }121 // Test creating a new API with a libp2p config122 rest, err := NewAPI(cfg)123 if err != nil {124 t.Fatal(err)125 }126 defer rest.Shutdown()127 badPid, _ := peer.IDB58Decode("QmTQ6oKHDwFjzr4ihirVCLJe8CxanxD3ZjGRYzubFuNDjE")128 cfg.ID = badPid129 err = cfg.Validate()130 if err == nil {131 t.Error("expected id-privkey mismatch")132 }133 cfg.ID = pid134 cfg.PrivateKey = nil135 err = cfg.Validate()136 if err == nil {137 t.Error("expected missing private key error")138 }139}140func TestToJSON(t *testing.T) {141 cfg := &Config{}142 cfg.LoadJSON(cfgJSON)143 newjson, err := cfg.ToJSON()144 if err != nil {145 t.Fatal(err)146 }147 cfg = &Config{}148 err = cfg.LoadJSON(newjson)149 if err != nil {150 t.Fatal(err)151 }152}153func TestDefault(t *testing.T) {154 cfg := &Config{}155 cfg.Default()156 if cfg.Validate() != nil {157 t.Fatal("error validating")158 }159 cfg.Default()160 cfg.IdleTimeout = -1161 if cfg.Validate() == nil {162 t.Fatal("expected error validating")163 }164}...

Full Screen

Full Screen

config.go

Source:config.go Github

copy

Full Screen

...45 if err != nil {46 return make([]string, 0), err47 }48 // var configParams configParam49 // loadJSON("./config/config.json", &configParams)50 return configParams.IPAddress, nil51}52// Port gets the port number list from config.json53func Port() ([]int, error) {54 configParams, err := parseJSON("./config.json")55 if err != nil {56 return make([]int, 0), err57 }58 // var configParams configParam59 // loadJSON("./config/config.json", &configParams)60 return configParams.Port, nil61}62// Port gets the portHB number list from config.json63func PortHB() ([]int, error) {64 configParams, err := parseJSON("./config.json")65 if err != nil {66 return make([]int, 0), err67 }68 // var configParams configParam69 // loadJSON("./config/config.json", &configParams)70 return configParams.PortHB, nil71}72func PortETC() ([]int, error) {73 configParams, err := parseJSON("./config.json")74 if err != nil {75 return make([]int, 0), err76 }77 // var configParams configParam78 // loadJSON("./config/config.json", &configParams)79 return configParams.PortETC, nil80}81func PortMJ() ([]int, error) {82 configParams, err := parseJSON("./config.json")83 if err != nil {84 return make([]int, 0), err85 }86 // var configParams configParam87 // loadJSON("./config/config.json", &configParams)88 return configParams.PortMJ, nil89}90// TimeOut gets the timeout number from config.json91func TimeOut() (int, error) {92 configParams, err := parseJSON("./config.json")93 if err != nil {94 return -1, err95 }96 // var configParams configParam97 // loadJSON("./config/config.json", &configParams)98 return configParams.TimeOut, nil99}100// K gets the k number from config.json101func K() (int, error) {102 configParams, err := parseJSON("./config.json")103 if err != nil {104 return -1, err105 }106 // var configParams configParam107 // loadJSON("./config/config.json", &configParams)108 return configParams.K, nil109}110// FailRate gets the FailRate from config.json111func FailRate() (int, error) {112 configParams, err := parseJSON("./config.json")113 if err != nil {114 return -1, err115 }116 // var configParams configParam117 // loadJSON("./config/config.json", &configParams)118 return configParams.FailRate, nil119}120func loadJSON(fileName string, key interface{}) {121 inFile, err := os.Open(fileName)122 checkError(err)123 decoder := json.NewDecoder(inFile)124 err = decoder.Decode(key)125 checkError(err)126 inFile.Close()127}128func checkError(err error) {129 if err != nil {130 fmt.Println("Fatal error ", err.Error())131 os.Exit(1)132 }133}...

Full Screen

Full Screen

loadJSON

Using AI Code Generation

copy

Full Screen

1cfg, err := config.LoadJSON("config.json")2if err != nil {3 log.Fatal(err)4}5cfg, err := config.LoadYAML("config.yaml")6if err != nil {7 log.Fatal(err)8}9cfg, err := config.LoadTOML("config.toml")10if err != nil {11 log.Fatal(err)12}13cfg, err := config.LoadHCL("config.hcl")14if err != nil {15 log.Fatal(err)16}17cfg, err := config.LoadHJSON("config.hjson")18if err != nil {19 log.Fatal(err)20}21cfg, err := config.LoadENV()22if err != nil {23 log.Fatal(err)24}

Full Screen

Full Screen

loadJSON

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 config.LoadJSON("./config.json")4 fmt.Println(config.Config)5 fmt.Println(config.Config.Database)6 fmt.Println(config.Config.Database.Host)7 fmt.Println(config.Config.Database.Port)8 fmt.Println(config.Config.Database.User)9 fmt.Println(config.Config.Database.Pwd)10 fmt.Println(config.Config.Database.Name)11 fmt.Println(config.Config.Database.Charset)12 fmt.Println(config.Config.Database.MaxOpenConn)13 fmt.Println(config.Config.Database.MaxIdleConn)14 fmt.Println(config.Config.Database.MaxLifeTime)15 fmt.Println(config.Config.Database.SslMode)16 fmt.Println(config.Config.Database.ConnMaxLifetime)17}18import (19func main() {20 config.LoadJSON("./config.json")21 fmt.Println(config.Config)22 fmt.Println(config.Config.Database)23 fmt.Println(config.Config.Database.Host)24 fmt.Println(config.Config.Database.Port)25 fmt.Println(config.Config.Database.User)26 fmt.Println(config.Config.Database.Pwd)27 fmt.Println(config.Config.Database.Name)28 fmt.Println(config.Config.Database.Charset)29 fmt.Println(config.Config.Database.MaxOpenConn)30 fmt.Println(config.Config.Database.MaxIdleConn)31 fmt.Println(config.Config.Database.MaxLifeTime)32 fmt.Println(config.Config.Database.SslMode)33 fmt.Println(config.Config.Database.ConnMaxLifetime)34}35import (36func main() {37 config.LoadJSON("./config.json")38 fmt.Println(config.Config)39 fmt.Println(config.Config.Database)40 fmt.Println(config.Config.Database.Host)41 fmt.Println(config.Config.Database.Port)42 fmt.Println(config.Config.Database.User)43 fmt.Println(config.Config.Database.Pwd)44 fmt.Println(config.Config.Database.Name)45 fmt.Println(config.Config.Database.Charset)46 fmt.Println(config.Config.Database.MaxOpenConn)47 fmt.Println(config.Config.Database.MaxIdleConn)48 fmt.Println(config.Config.Database.MaxLifeTime)49 fmt.Println(config.Config.Database.SslMode)50 fmt.Println(config.Config.Database.ConnMaxLifetime)51}52import (53func main() {54 config.LoadJSON("./config.json")55 fmt.Println(config.Config)56 fmt.Println(config.Config.Database)57 fmt.Println(config.Config.Database.Host)58 fmt.Println(config.Config.Database.Port)59 fmt.Println(config.Config.Database.User)60 fmt.Println(config.Config.Database.Pwd)61 fmt.Println(config.Config.Database

Full Screen

Full Screen

loadJSON

Using AI Code Generation

copy

Full Screen

1func main() {2 dir, err := os.Getwd()3 if err != nil {4 log.Fatal(err)5 }6 config := Config{}7 data := config.loadJSON(dir + "/1.json")8 fmt.Println(data)9}

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Selenoid automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful