From af9138ab6fb3fa03405a197bdccccaea9e8869cb Mon Sep 17 00:00:00 2001 From: crusader Date: Thu, 13 Jul 2017 21:36:20 +0900 Subject: [PATCH] ing --- config.yml | 13 +++++++++++++ config/config.go | 42 ++++++++++++++++++++++++++++++++++++++++++ glide.yaml | 1 + 3 files changed, 56 insertions(+) create mode 100644 config.yml create mode 100644 config/config.go diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..55e8a1b --- /dev/null +++ b/config.yml @@ -0,0 +1,13 @@ + +websocket: + writeTimeout: 0 + readTimeout: 0 + pongTimeout: 60 + pingTimeout: 10 + maxMessageSize: 1024 + readBufferSize: 4096 + writeBufferSize: 4096 +grpc: + host: localhost + port: 8000 + tls: false diff --git a/config/config.go b/config/config.go new file mode 100644 index 0000000..3b11f83 --- /dev/null +++ b/config/config.go @@ -0,0 +1,42 @@ +package config + +import ( + "io/ioutil" + + "gopkg.in/yaml.v2" +) + +type Config struct { + websocket Websocket `yaml:"websocket"` + grpc GRPC `yaml:"grpc"` +} + +type Websocket struct { + writeTimeout int8 `yaml:"writeTimeout"` + readTimeout int8 `yaml:"readTimeout"` + pongTimeout int8 `yaml:"pongTimeout"` + pingTimeout int8 `yaml:"pingTimeout"` + maxMessageSize int64 `yaml:"maxMessageSize"` + readBufferSize int `yaml:"readBufferSize"` + writeBufferSize int `yaml:"writeBufferSize"` +} + +type GRPC struct { + host string `yaml:"host"` + port int16 `yaml:"port"` + tls bool `yaml:"tls"` +} + +func LoadConfig(filename string) (*Config, error) { + bytes, err := ioutil.ReadFile(filename) + if err != nil { + return nil, err + } + c := new(Config) + err = yaml.Unmarshal(bytes, &c) + if err != nil { + return nil, err + } + + return c, nil +} diff --git a/glide.yaml b/glide.yaml index 6960547..f10afe3 100644 --- a/glide.yaml +++ b/glide.yaml @@ -16,3 +16,4 @@ import: - package: git.loafle.net/overflow/overflow_api_server subpackages: - golang +- package: gopkg.in/yaml.v2