Documentation
¶
Index ¶
- Variables
- func NewAuthInterceptor(config AuthConfig) *headerInterceptor
- func NewClient(config ClientConfig, opts ...connect.ClientOption) (v1connect.GroupAddressServiceClient, error)
- type AuthConfig
- type ClientConfig
- type Config
- type KNXConfig
- type MetricsConfig
- type RPCConfig
- type Server
- func (s *Server) Publish(ctx context.Context, req *connect.Request[v1.PublishRequest]) (*connect.Response[v1.PublishResponse], error)
- func (s *Server) Start(ctx context.Context) error
- func (s *Server) Subscribe(ctx context.Context, req *connect.Request[v1.SubscribeRequest], ...) error
- func (s *Server) SubscribeUnary(ctx context.Context, req *connect.Request[v1.SubscribeUnaryRequest]) (*connect.Response[v1.SubscribeUnaryResponse], error)
- type SwaggerConfig
- type WebserverConfig
Constants ¶
This section is empty.
Variables ¶
var (
ErrInvalidAuthCredentials = errors.New("invalid auth credentials")
)
Functions ¶
func NewAuthInterceptor ¶
func NewAuthInterceptor(config AuthConfig) *headerInterceptor
NewAuthInterceptor returns a [headerInterceptor] to add authentication
func NewClient ¶
func NewClient(config ClientConfig, opts ...connect.ClientOption) (v1connect.GroupAddressServiceClient, error)
NewClient returns a fresh GroupAddressServiceClient from config
Types ¶
type AuthConfig ¶
type AuthConfig struct {
// Enabled whether to require and check authentication
Enabled bool `mapstructure:"enabled" default:"false"`
// Header is the header to fetch the key, required if [Enabled]
Header string `mapstructure:"header" default:"Authorization"`
// Scheme defines the auth scheme which is stripped from the header value
Scheme string `mapstructure:"scheme" default:"Bearer"`
// SecretKey is the key to compare the Header value with, required if [Enabled]
SecretKey string `mapstructure:"secretKey" default:""`
}
AuthConfig holds the auth configuration
func (*AuthConfig) Validate ¶
func (c *AuthConfig) Validate() error
Validate validates the AuthConfig
type ClientConfig ¶
type ClientConfig struct {
// Host is the knxrpc host to connect to
Host string `mapstructure:"host"`
// Port is the knxrpc host to connect to
Port int `mapstructure:"port"`
// Auth config to use
Auth AuthConfig `mapstructure:"auth"`
// UseTLS whether to connect using TLS
UseTLS bool `mapstructure:"useTLS"`
// InsecureTLS whether to use insecureSkipVerify
InsecureTLS bool `mapstructure:"insecureTLS"`
}
ClientConfig holds the knxrpc client config
func (*ClientConfig) Validate ¶
func (c *ClientConfig) Validate() error
Validate validates the ClientConfig
type Config ¶
type Config struct {
// Log stores logging config
Log loggingfx.Config `mapstructure:"log"`
// KNX is the KNX bus config, required
KNX KNXConfig `mapstructure:"knx"`
// RPC is the rpc config, required
RPC RPCConfig `mapstructure:"rpc"`
// Client is the client config to test the server, optional
Client ClientConfig `mapstructure:"knxrpc"`
}
Config holds the required config for New
type KNXConfig ¶
type KNXConfig struct {
// GatwewayHost is the Host or IP address of a KNX gateway, required
GatwewayHost string `mapstructure:"gatewayHost"`
// GatwewayPort is the port to use when communicating, defaults to 3671
GatwewayPort int `mapstructure:"gatewayPort" default:"3671"`
// Timeout is the default timeout for any bus activity or operation
Timeout time.Duration `mapstructure:"timeout" default:"10s"`
// InactivityTimeout is the timeout after which the servers errors if no bus activity was seen
InactivityTimeout time.Duration `mapstructure:"inactivityTimeout" default:"5m"`
// SendLocalAddress sends the local address when establishing a tunnel (breaks NAT)
SendLocalAddress bool `mapstructure:"sendLocalAddress" default:"false"`
// UseTCP establishes the tunnel using tcp instead of udp
UseTCP bool `mapstructure:"useTCP" default:"false"`
}
KNXConfig holds the KNX bus config
type MetricsConfig ¶
type MetricsConfig struct {
// Enabled whether to serve swaggerui
Enabled bool `mapstructure:"enabled" default:"false"`
// Path to serve mectris on
Path string `mapstructure:"path" default:"/metrics"`
// Auth config to use
Auth AuthConfig `mapstructure:"auth"`
}
MetricsConfig holds the metrics configuration
func (*MetricsConfig) Validate ¶
func (c *MetricsConfig) Validate() error
Validate validates the MetricsConfig
type RPCConfig ¶
type RPCConfig struct {
// Auth config to use
Auth AuthConfig `mapstructure:"auth"`
// Webserver config to use
Webserver WebserverConfig `mapstructure:"webserver"`
}
RPCConfig holds the RPC config
type Server ¶
type Server struct {
http.Handler
v1Connect.UnimplementedGroupAddressServiceHandler
// contains filtered or unexported fields
}
Server implements RPCs using a http.Handler.
func New ¶
New returns a new *KNXConnect or error Use [Start] to connect the KNX tunnel and start dispatching messages.
func (*Server) Publish ¶
func (s *Server) Publish( ctx context.Context, req *connect.Request[v1.PublishRequest], ) (*connect.Response[v1.PublishResponse], error)
Publish implements knx.groupaddressservice.v1.Publish
func (*Server) Start ¶
Start will connect to the KNX bus and start message handling or error. You may cancel ctx any time to close the tunnel and stop message handling.
func (*Server) Subscribe ¶
func (s *Server) Subscribe( ctx context.Context, req *connect.Request[v1.SubscribeRequest], stream *connect.ServerStream[v1.SubscribeResponse], ) error
Subscribe implements knx.groupaddressservice.v1.Subscribe
func (*Server) SubscribeUnary ¶
func (s *Server) SubscribeUnary( ctx context.Context, req *connect.Request[v1.SubscribeUnaryRequest], ) (*connect.Response[v1.SubscribeUnaryResponse], error)
SubscribeUnary implements knx.groupaddressservice.v1.SubscribeUnary
type SwaggerConfig ¶
type SwaggerConfig struct {
// Enabled whether to serve swaggerui
Enabled bool `mapstructure:"enabled" default:"false"`
// Path to serve swagger on
Path string `mapstructure:"path" default:"/swagger"`
// RootRedirect redirects / to <Path>/ if enabled
RootRedirect bool `mapstructure:"rootRedirect" default:"false"`
}
SwaggerConfig holds the swagger configuration
func (*SwaggerConfig) Validate ¶
func (c *SwaggerConfig) Validate() error
Validate validates the SwaggerConfig
type WebserverConfig ¶
type WebserverConfig struct {
// Enabled whether to start a http listener for the rpc server
Enabled bool `mapstructure:"enabled" default:"false"`
// Host is the listening host to use when starting a server
Host string `mapstructure:"host" default:"127.0.0.1"`
// Port is the listening port to use when starting a server
Port int `mapstructure:"port" default:"8080"`
// LogRequests whether to log requests
LogRequests bool `mapstructure:"logRequests"`
// Swagger config to use
Swagger SwaggerConfig `mapstructure:"swagger"`
// Metrics config to use
Metrics MetricsConfig `mapstructure:"metrics"`
}
WebserverConfig holds the webserver config
func (*WebserverConfig) Validate ¶
func (c *WebserverConfig) Validate() error
Validate validates the HTTPConfig