mirror of
https://gitlab.com/comunic/ComunicRTCProxy
synced 2024-12-25 04:58:55 +00:00
Load configuration
This commit is contained in:
parent
0ce15f51d9
commit
4990ecea0f
2
.vscode/launch.json
vendored
2
.vscode/launch.json
vendored
@ -11,7 +11,7 @@
|
||||
"mode": "auto",
|
||||
"program": "${fileDirname}",
|
||||
"env": {},
|
||||
"args": []
|
||||
"args": ["config.yaml"]
|
||||
}
|
||||
]
|
||||
}
|
36
config.go
36
config.go
@ -1,6 +1,36 @@
|
||||
package main
|
||||
|
||||
// Value Main value
|
||||
func Name() string {
|
||||
return "pierre"
|
||||
import (
|
||||
"io/ioutil"
|
||||
"log"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// Config stores application configuration
|
||||
type Config struct {
|
||||
Secure bool
|
||||
Hostname string
|
||||
Port int
|
||||
Path string
|
||||
Token string
|
||||
}
|
||||
|
||||
// Load the configuration
|
||||
func loadConfig(path string) Config {
|
||||
|
||||
// Load data
|
||||
dat, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
log.Fatalf("Could not read configuration: %v", err)
|
||||
}
|
||||
|
||||
// Decode data
|
||||
conf := Config{}
|
||||
err = yaml.UnmarshalStrict(dat, &conf)
|
||||
if err != nil {
|
||||
log.Fatalf("Could not decode configuration: %v", err)
|
||||
}
|
||||
|
||||
return conf
|
||||
}
|
||||
|
9
config.yaml
Normal file
9
config.yaml
Normal file
@ -0,0 +1,9 @@
|
||||
# Proxy configuration
|
||||
#
|
||||
# @author Pierre Hubert
|
||||
|
||||
secure: false
|
||||
hostname: 127.0.0.1
|
||||
port: 3000
|
||||
path: /rtc_proxy/ws
|
||||
token: SecretToken
|
3
go.sum
Normal file
3
go.sum
Normal file
@ -0,0 +1,3 @@
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.8 h1:obN1ZagJSUGI0Ek/LBmuj4SNLPfIny3KsKFopxRdj10=
|
||||
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
15
main.go
15
main.go
@ -2,8 +2,21 @@ package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
fmt.Println("secret", Name())
|
||||
|
||||
println("Comunic RTC Proxy. (c) Pierre Hubert 2020")
|
||||
|
||||
// Command line args
|
||||
if len(os.Args) != 2 {
|
||||
fmt.Printf("Usage: %s <config>", os.Args[0])
|
||||
}
|
||||
|
||||
// First, load the config
|
||||
conf := loadConfig(os.Args[1])
|
||||
|
||||
fmt.Println(conf)
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user