From 91e17d0cdeb123fd7c133571b22ef8cf3856b079 Mon Sep 17 00:00:00 2001 From: Alex Unger Date: Fri, 27 Dec 2019 13:09:27 +0100 Subject: [PATCH] Add Namespace flag (#21) * added http-namespace to the flagset * update description * added namespace option to the options list * added namespace as a config parameter * updated docs * fix default value override --- docs/content/getting-started.md | 3 +++ pkg/config/config.go | 5 +++-- pkg/flagset/flagset.go | 7 +++++++ pkg/server/http/option.go | 18 +++++++++++++----- pkg/server/http/server.go | 2 +- 5 files changed, 27 insertions(+), 8 deletions(-) diff --git a/docs/content/getting-started.md b/docs/content/getting-started.md index c81ddf3f1..ea7072d37 100644 --- a/docs/content/getting-started.md +++ b/docs/content/getting-started.md @@ -129,6 +129,9 @@ If you prefer to configure the service with commandline flags you can see the av --http-addr : Address to bind http server, defaults to `0.0.0.0:9120` +--http-namespace +: Namespace for internal services communication, defaults to `com.owncloud.web` + --http-root : Root path of http server, defaults to `/` diff --git a/pkg/config/config.go b/pkg/config/config.go index 902754e98..9cf8710dc 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -17,8 +17,9 @@ type Debug struct { // HTTP defines the available http configuration. type HTTP struct { - Addr string - Root string + Addr string + Namespace string + Root string } // Tracing defines the available tracing configuration. diff --git a/pkg/flagset/flagset.go b/pkg/flagset/flagset.go index 240aa04ab..32eb7a82f 100644 --- a/pkg/flagset/flagset.go +++ b/pkg/flagset/flagset.go @@ -127,6 +127,13 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag { EnvVar: "GRAPH_HTTP_ROOT", Destination: &cfg.HTTP.Root, }, + &cli.StringFlag{ + Name: "http-namespace", + Value: "com.owncloud.web", + Usage: "Set the base namespace for the http service for service discovery", + EnvVar: "GRAPH_HTTP_NAMESPACE", + Destination: &cfg.HTTP.Namespace, + }, &cli.StringFlag{ Name: "ldap-network", Value: "tcp", diff --git a/pkg/server/http/option.go b/pkg/server/http/option.go index a59564e8b..cda89c0c2 100644 --- a/pkg/server/http/option.go +++ b/pkg/server/http/option.go @@ -14,11 +14,12 @@ type Option func(o *Options) // Options defines the available options for this package. type Options struct { - Logger log.Logger - Context context.Context - Config *config.Config - Metrics *metrics.Metrics - Flags []cli.Flag + Logger log.Logger + Context context.Context + Config *config.Config + Metrics *metrics.Metrics + Flags []cli.Flag + Namespace string } // newOptions initializes the available default options. @@ -66,3 +67,10 @@ func Flags(val []cli.Flag) Option { o.Flags = append(o.Flags, val...) } } + +// Namespace provides a function to set the Namespace option. +func Namespace(val string) Option { + return func(o *Options) { + o.Namespace = val + } +} diff --git a/pkg/server/http/server.go b/pkg/server/http/server.go index b04bbaf2d..fddfd8f66 100644 --- a/pkg/server/http/server.go +++ b/pkg/server/http/server.go @@ -14,7 +14,7 @@ func Server(opts ...Option) (http.Service, error) { service := http.NewService( http.Logger(options.Logger), - http.Namespace("go.micro.web"), + http.Namespace(options.Config.HTTP.Namespace), http.Name("graph"), http.Version(version.String), http.Address(options.Config.HTTP.Addr),