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 <tom.wilkie@gmail.com>
  • Loading branch information
tomwilkie committed Jan 5, 2019
1 parent 630fc6a commit ea68238
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 18 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
34 changes: 17 additions & 17 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,27 +26,27 @@ 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:"-"`

PathPrefix string
PathPrefix string `yaml:"http_path_prefix"`
}

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

0 comments on commit ea68238

Please sign in to comment.