Moving cruftier services that are only used for tests under a test repo

This commit is contained in:
Janos Dobronszki
2020-10-15 16:54:27 +02:00
parent 7c2f9737cb
commit d86531e5e9
37 changed files with 0 additions and 0 deletions

3
test/conf/README.md Normal file
View File

@@ -0,0 +1,3 @@
# Conf
A service which demonstrates how to read and write config

59
test/conf/main.go Normal file
View File

@@ -0,0 +1,59 @@
package main
import (
"fmt"
"time"
"github.com/micro/micro/v3/service"
"github.com/micro/micro/v3/service/config"
)
type keyConfig struct {
Subkey string `json:"subkey"`
Subkey1 int `json:"subkey1"`
Subkey2 string `json:"subkey2"`
}
type conf struct {
Key keyConfig `json:"key"`
}
func main() {
// get a value
go func() {
for {
time.Sleep(time.Second)
// Test merge
err := config.Set("key", map[string]interface{}{
"Subkey3": "Merge",
})
if err != nil {
fmt.Println("ERROR: ", err)
}
val, _ := config.Get("key.subkey3")
if val.String("") != "Merge" {
fmt.Println("ERROR: key.subkey3 should be 'Merge' but it is:", val.String(""))
}
val, err = config.Get("key.subkey")
fmt.Println("Value of key.subkey: ", val.String(""), err)
val, _ = config.Get("key", config.Secret(true))
c := conf{}
err = val.Scan(&c.Key)
fmt.Println("Value of key.subkey1: ", c.Key.Subkey1, err)
fmt.Println("Value of key.subkey2: ", c.Key.Subkey2)
val, _ = config.Get("key.subkey3")
fmt.Println("Value of key.subkey3: ", val.String(""))
// Test defaults
val, _ = config.Get("key.subkey_does_not_exist")
fmt.Println("Default", val.String("Hello"))
}
}()
// run the service
service.Run()
}