Skip to content

Commit

Permalink
Allow server.Config to be unmarshaled from YAML.
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Wilkie <[email protected]>
  • Loading branch information
tomwilkie committed Nov 30, 2018
1 parent 526f1ec commit dc4f97a
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 17 deletions.
11 changes: 10 additions & 1 deletion logging/level.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,16 @@ func (l *Level) String() string {
return l.s
}

// Set updates the value of the allowed level.
// UnmarshalYAML implements yaml.Unmarshaler.
func (l *Level) UnmarshalYAML(unmarshal func(interface{}) error) error {
var level string
if err := unmarshal(&level); err != nil {
return err
}
return l.Set(level)
}

// Set updates the value of the allowed level. Implments flag.Value.
func (l *Level) Set(s string) error {
switch s {
case "debug":
Expand Down
32 changes: 16 additions & 16 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
"time"

"github.com/gorilla/mux"
"github.com/grpc-ecosystem/go-grpc-middleware"
grpc_middleware "github.com/grpc-ecosystem/go-grpc-middleware"
otgrpc "github.com/opentracing-contrib/go-grpc"
"github.com/opentracing/opentracing-go"
"github.com/prometheus/client_golang/prometheus"
Expand All @@ -26,25 +26,25 @@ import (

// Config for a Server
type Config struct {
MetricsNamespace string
HTTPListenPort int
GRPCListenPort int
MetricsNamespace string `yaml:"-"`
HTTPListenPort int `yaml:"http_listen_port"`
GRPCListenPort int `yaml:"grpc_listen_port"`

RegisterInstrumentation bool
ExcludeRequestInLog bool
RegisterInstrumentation bool `yaml:"-"`
ExcludeRequestInLog bool `yaml:"-"`

ServerGracefulShutdownTimeout time.Duration
HTTPServerReadTimeout time.Duration
HTTPServerWriteTimeout time.Duration
HTTPServerIdleTimeout time.Duration
ServerGracefulShutdownTimeout time.Duration `yaml:"graceful_shutdown_timeout"`
HTTPServerReadTimeout time.Duration `yaml:"http_server_read_timeout"`
HTTPServerWriteTimeout time.Duration `yaml:"http_server_write_timeout"`
HTTPServerIdleTimeout time.Duration `yaml:"http_server_idle_timeout"`

GRPCOptions []grpc.ServerOption
GRPCMiddleware []grpc.UnaryServerInterceptor
GRPCStreamMiddleware []grpc.StreamServerInterceptor
HTTPMiddleware []middleware.Interface
GRPCOptions []grpc.ServerOption `yaml:"-"`
GRPCMiddleware []grpc.UnaryServerInterceptor `yaml:"-"`
GRPCStreamMiddleware []grpc.StreamServerInterceptor `yaml:"-"`
HTTPMiddleware []middleware.Interface `yaml:"-"`

LogLevel logging.Level
Log logging.Interface
LogLevel logging.Level `yaml:"log_level"`
Log logging.Interface `yaml:"-"`
}

// RegisterFlags adds the flags required to config this to the given FlagSet
Expand Down

0 comments on commit dc4f97a

Please sign in to comment.