httpservice

package
v0.0.0-...-480f137 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2024 License: MPL-2.0 Imports: 25 Imported by: 1

Documentation

Overview

Package httpservice provides an HTTP service that accepts a twicmd.Service and provides it over HTTP as a Protobuf REST API.

API Specification

For each service, the following endpoints are provided:

  • GET / - returns the service description in Protobuf format.
  • POST /execute - accepts a command in Protobuf format and returns the result message body in Protobuf format.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client wraps an HTTP API and implements twicmd.Service.

func NewClient

func NewClient(serviceName, baseURL string, logger *slog.Logger) *Client

NewClient creates a new HTTP service with the given URL.

func (*Client) ApplyConfigurationValues

func (s *Client) ApplyConfigurationValues(ctx context.Context, req *twicmdcfgpb.ApplyRequest) (*twicmdcfgpb.ApplyResponse, error)

func (*Client) ConfigurationValues

func (s *Client) ConfigurationValues(ctx context.Context, req *twicmdcfgpb.OptionsRequest) (*twicmdcfgpb.OptionsResponse, error)

func (*Client) Execute

Execute implements twicmd.Service.

func (*Client) Name

func (s *Client) Name() string

Name implements twicmd.Service.

func (*Client) Service

func (s *Client) Service(ctx context.Context) (*twicmdproto.Service, error)

Service implements twicmd.Service.

func (*Client) Start

func (s *Client) Start(ctx context.Context) error

Start implements twid.Starter.

func (*Client) SubscribeMessages

func (s *Client) SubscribeMessages(ch chan<- *twismsproto.Message, filters *twismsproto.MessageFilters)

SubscribeMessages implements twisms.MessageSubscriber.

func (*Client) UnsubscribeMessages

func (s *Client) UnsubscribeMessages(ch chan<- *twismsproto.Message)

UnsubscribeMessages implements twisms.MessageSubscriber.

type ClientConfig

type ClientConfig struct {
	// Name is the name of the service.
	Name string `json:"name"`
	// BaseURL is the base BaseURL of the HTTP service.
	BaseURL string `json:"base_url"`
}

ClientConfig is the expected configuration for an HTTP service.

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

Handler wraps a twicmd.Service and turns it into an HTTP server.

func NewHandler

func NewHandler(service twicmd.Service, logger *slog.Logger) *Handler

NewHandler creates a new HTTP server with the given service.

func (*Handler) Close

func (s *Handler) Close() error

Close frees resources used by the server.

func (*Handler) ServeHTTP

func (s *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL