diff --git a/context.go b/context.go index e54ad7c..d292600 100644 --- a/context.go +++ b/context.go @@ -42,7 +42,6 @@ import ( type ( Context struct { - http.Handler okapi *Okapi // Request is the http.Request object Request *http.Request @@ -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), } @@ -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 @@ -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 diff --git a/okapi.go b/okapi.go index acea469..6646243 100644 --- a/okapi.go +++ b/okapi.go @@ -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) { @@ -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)) } @@ -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,