Skip to content

Commit

Permalink
♻️ refactor: updated server model #9
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Nov 4, 2023
1 parent 18287d6 commit 5ff9972
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import (

func NewServer() *Server {
s := &Server{}
s.SetAttr(*NewAttribute())
s.SetTimeout(*NewTimeout().SetRead(15 * time.Second).SetWrite(15 * time.Second))
return s
}

Expand All @@ -35,6 +37,11 @@ func (s *Server) SetMode(value string) *Server {
return s
}

func (s *Server) SetAttr(value Attr) *Server {
s.Attr = value
return s
}

func (s *Server) Json() string {
return utils.ToJson(s)
}
Expand Down Expand Up @@ -84,3 +91,17 @@ func GetTimeoutSample() *Timeout {
SetServe(10 * time.Second)
return t
}

func NewAttribute() *Attr {
return &Attr{
MaxHeaderBytes: 1 << 20,
}
}

func (a *Attr) SetMaxHeaderBytes(value int) *Attr {
if value < 0 {
log.Panicf("Invalid max_header_bytes: %v", value)
}
a.MaxHeaderBytes = value
return a
}
5 changes: 5 additions & 0 deletions server/server_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ type Server struct {
Port int `json:"port" binding:"required" yaml:"port"`
Mode string `json:"mode" yaml:"mode"`
Timeout Timeout `json:"timeout" yaml:"timeout"`
Attr Attr `json:"attr" yaml:"attr"`
}

type Timeout struct {
Expand All @@ -15,3 +16,7 @@ type Timeout struct {
Write time.Duration `json:"write" yaml:"write"`
Idle time.Duration `json:"idle" yaml:"idle"`
}

type Attr struct {
MaxHeaderBytes int `json:"max_header_bytes" yaml:"max_header_bytes"`
}

0 comments on commit 5ff9972

Please sign in to comment.