Documentation
¶
Overview ¶
Copyright © 2024 Vicknesh Suppramaniam <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2024 Vicknesh Suppramaniam <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2024 Vicknesh Suppramaniam <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2024 Vicknesh Suppramaniam <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2025 Vicknesh Suppramaniam <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2024 Vicknesh Suppramaniam <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2024 Vicknesh Suppramaniam <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2024 Vicknesh Suppramaniam <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2024 Vicknesh Suppramaniam <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Copyright © 2024 Vicknesh Suppramaniam <[email protected]>
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
- Constants
- func HealthCheckHandler(w http.ResponseWriter, r *http.Request)
- type CORS
- type Config
- type Group
- type Handler
- type Header
- type Listener
- func (l *Listener) CORS(c *CORS)
- func (l *Listener) Init(logger *slog.Logger, address string, port int, tlsConfig *tls.Config) (err error)
- func (l *Listener) Name() (str string)
- func (l *Listener) SetConfig(config any) (err error)
- func (l *Listener) SetCustomHeaders(header *Header)
- func (l *Listener) SetWSHandler(h WSHandler)
- func (l *Listener) Start() (err error)
- func (l *Listener) Stop(ctx context.Context) error
- type Method
- type Router
- type WSConfig
- type WSHandler
- type WSHub
Constants ¶
const ( // PatternAll - helper constant for all PatternAll = "/*" // HealthEndpoint - default endpoint for healthchecks HealthEndpoint = "healthcheck" )
const ( // DefaultAddr - listen on all IPv4 and IPv6 interfaces DefaultAddr = "[::]" // DefaultPort - default port to listen on DefaultPort = 8081 )
Variables ¶
This section is empty.
Functions ¶
func HealthCheckHandler ¶
func HealthCheckHandler(w http.ResponseWriter, r *http.Request)
HealthCheckHandler - helper function to handle Options method
Types ¶
type CORS ¶
type CORS struct {
AllowedOrigins []string
AllowedMethods []string
AllowedHeaders []string
MaxAge int // maximum number of seconds the results can be cached
Debug bool // debug CORS detauls
AllowCredentials bool // indicates if this REST service should release the response to cross-origin requests (typically JavaScript code); cross-origin are those that don't match the defined origins
// contains filtered or unexported fields
}
CORS - Cross Origin Resource Sharing configuration
func (*CORS) SetCustomHeaders ¶ added in v1.2.1
SetCustomHeaders - set custom headers to be returned with CORS request
func (*CORS) SetHeaders ¶
SetHeaders - sets HTTP headers allowed for this REST service
func (*CORS) SetMethods ¶
SetMethods - sets HTTP methods allowed for this REST service
func (*CORS) SetOrigins ¶
SetOrigins - sets origins allowed for this REST service
type Config ¶
type Config struct {
CORS *CORS
MaxConcurrent int
Timeout time.Duration
WS *WSConfig
// contains filtered or unexported fields
}
Config - listener specific configuration
func (*Config) EnableCompress ¶
EnableCompress - enable or disable gzip compression
func (*Config) EnableWebSockets ¶ added in v1.2.0
type Group ¶
type Group struct {
// contains filtered or unexported fields
}
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler - method, path and function to run
func NewHandler ¶ added in v1.2.1
func NewHandler() (handler *Handler)
NewHandler - create new instance of handler
type Header ¶ added in v1.0.3
Header - sets custom header to be returned for the request
type Listener ¶
type Listener struct {
// contains filtered or unexported fields
}
Listener - implementation of REST listener
func (*Listener) Init ¶
func (l *Listener) Init(logger *slog.Logger, address string, port int, tlsConfig *tls.Config) (err error)
Init - initializes this listener with any necessary configuration parameters
func (*Listener) SetCustomHeaders ¶ added in v1.0.3
SetCustomHeaders - sets custom headers to be injected to all requests
func (*Listener) SetWSHandler ¶ added in v1.2.0
SetWSHandler - application-level per-connection WebSocket handler
type Router ¶
type Router struct {
// contains filtered or unexported fields
}
Router - specific path handler
func (*Router) AddGroup ¶ added in v1.2.1
AddGroup - adds given group to the base of the router, with custom middlewares for an entire group (optional) with group middlewares being executed before handler middlewares
func (*Router) AddHealthCheck ¶
func (router *Router) AddHealthCheck(rootPath string, hFn http.HandlerFunc)
AddHealthCheck - creates a healthcheck endpoint at the root of the router using the GET verb, without using `base` but still respecting all middlewares for the router only
func (*Router) SetHandler ¶
SetHandler - set given handlers for this router instance
type WSConfig ¶ added in v1.2.0
type WSConfig struct {
Enabled bool
Path string // e.g. "/ws"
AllowedOrigins []string // exact origins; "*" = allow all (not recommended)
BearerSecret string // optional: if set, require Authorization: Bearer <secret>
IdleTimeout time.Duration // optional: idle limit for a conn; 0 = disabled
MaxReadBytes int64 // per-message read limit; 0 = library default
WriteTimeout time.Duration // per write; 0 = no extra timeout
KeepAlive time.Duration // ping interval; 0 = disabled
Backlog int // outbound queue per client; drop if full
}
WSConfig - WebSocket settings
type WSHandler ¶ added in v1.2.0
WSHandler - app-level handler per accepted connection. Your application sets this; it runs per-connection after a successful upgrade.
type WSHub ¶ added in v1.2.0
type WSHub struct {
// contains filtered or unexported fields
}