From 0d93b2c31c7937f43942f1d47a88ad897b21b89e Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Thu, 26 Nov 2020 01:13:05 +0300 Subject: [PATCH] add some defaults Signed-off-by: Vasiliy Tolstov --- codec/codec.go | 8 ++++---- server/options.go | 2 ++ server/server.go | 27 ++++++++++++++------------- 3 files changed, 20 insertions(+), 17 deletions(-) diff --git a/codec/codec.go b/codec/codec.go index 74b07e6c..fa5c98e9 100644 --- a/codec/codec.go +++ b/codec/codec.go @@ -23,7 +23,7 @@ var ( ) var ( - DefaultMaxMessageSize = 1024 * 1024 * 4 // 4Mb + DefaultMaxMsgSize = 1024 * 1024 * 4 // 4Mb ) // MessageType @@ -62,12 +62,12 @@ type Message struct { type Option func(*Options) type Options struct { - MaxMessageSize int64 + MaxMsgSize int64 } -func MaxMessageSize(n int64) Option { +func MaxMsgSize(n int64) Option { return func(o *Options) { - o.MaxMessageSize = n + o.MaxMsgSize = n } } diff --git a/server/options.go b/server/options.go index aa91f956..fb4a31e1 100644 --- a/server/options.go +++ b/server/options.go @@ -16,6 +16,8 @@ import ( "github.com/unistack-org/micro/v3/tracer" ) +type Option func(*Options) + // Options server struct type Options struct { Codecs map[string]codec.Codec diff --git a/server/server.go b/server/server.go index 5fb1a3b3..9badf18e 100644 --- a/server/server.go +++ b/server/server.go @@ -15,6 +15,20 @@ var ( DefaultServer Server = NewServer() ) +var ( + DefaultAddress = ":0" + DefaultName = "server" + DefaultVersion = "latest" + DefaultId = uuid.New().String() + DefaultRegisterCheck = func(context.Context) error { return nil } + DefaultRegisterInterval = time.Second * 30 + DefaultRegisterTTL = time.Second * 90 + DefaultNamespace = "micro" + DefaultMaxMsgSize = 1024 * 1024 * 4 // 4Mb + DefaultMaxMsgRecvSize = 1024 * 1024 * 4 // 4Mb + DefaultMaxMsgSendSize = 1024 * 1024 * 4 // 4Mb +) + // Server is a simple micro server abstraction type Server interface { // Initialise options @@ -134,16 +148,3 @@ type Subscriber interface { Endpoints() []*registry.Endpoint Options() SubscriberOptions } - -type Option func(*Options) - -var ( - DefaultAddress = ":0" - DefaultName = "server" - DefaultVersion = "latest" - DefaultId = uuid.New().String() - DefaultRegisterCheck = func(context.Context) error { return nil } - DefaultRegisterInterval = time.Second * 30 - DefaultRegisterTTL = time.Second * 90 - DefaultNamespace = "micro" -)