Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 4 additions & 5 deletions context.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ import (

type (
Context struct {
http.Handler
okapi *Okapi
// Request is the http.Request object
Request *http.Request
Expand Down Expand Up @@ -78,8 +77,8 @@ const (

// ************** Accessors *************

// NewStoreData creates a new instance of Store
func NewStoreData() *Store {
// newStoreData creates a new instance of Store
func newStoreData() *Store {
return &Store{
data: make(map[string]any),
}
Expand Down Expand Up @@ -116,7 +115,7 @@ func (c *Context) GetTime(key string) (time.Time, bool) {
// Initializes the data map if it doesn't exist.
func (c *Context) Set(key string, value any) {
if c.store == nil {
c.store = NewStoreData()
c.store = newStoreData()
}
c.store.mu.Lock()
c.store.data[key] = value
Expand Down Expand Up @@ -164,7 +163,7 @@ func (c *Context) Copy() *Context {
newCtx := &Context{
Request: c.Request, // Copy request reference
Response: c.Response, // Copy response reference
store: NewStoreData(), // Initialize new data map
store: newStoreData(), // Initialize new data map
params: c.params, // Copy params
}
// Copy all key-value pairs to the new context
Expand Down
16 changes: 15 additions & 1 deletion okapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,15 @@ func WithAddr(addr string) OptionFunc {
}
}

// WithRenderer sets the server Renderer
func WithRenderer(renderer Renderer) OptionFunc {
return func(o *Okapi) {
if renderer != nil {
o.Renderer = renderer
}
}
}

// WithOpenAPIDisabled disabled OpenAPI Docs
func WithOpenAPIDisabled() OptionFunc {
return func(o *Okapi) {
Expand Down Expand Up @@ -357,6 +366,11 @@ func (o *Okapi) WithDebug() *Okapi {
return o.apply(WithDebug())
}

// WithRenderer sets the server Renderer
func (o *Okapi) WithRenderer(renderer Renderer) *Okapi {
return o.apply(WithRenderer(renderer))
}

func (o *Okapi) WithPort(port int) *Okapi {
return o.apply(WithPort(port))
}
Expand Down Expand Up @@ -1062,7 +1076,7 @@ func initConfig(options ...OptionFunc) *Okapi {
context: &Context{
Request: new(http.Request),
Response: &response{},
store: NewStoreData(),
store: newStoreData(),
},
router: newRouter(),
server: server,
Expand Down