Documentation ¶
Overview ¶
The httpservice package provides a way to run a simple HTTP server service as a charm. It does not provide any way to interact with the running service - for more control, see the httprelation and service packages, which the httpservice package uses for its implementation.
Index ¶
- Variables
- type Service
- func (svc *Service) HTTPPort() int
- func (svc *Service) HTTPSPort() int
- func (svc *Service) PublicHTTPSURL() (string, error)
- func (svc *Service) PublicHTTPURL() (string, error)
- func (svc *Service) Register(r *hook.Registry, serviceName, relationName string, handler interface{})
- func (svc *Service) Restart() error
- func (svc *Service) Start(arg interface{}) error
- func (svc *Service) Stop() error
Constants ¶
This section is empty.
Variables ¶
var ErrHTTPSNotConfigured = errgo.New("HTTPS not configured")
Functions ¶
This section is empty.
Types ¶
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service represents an HTTP service. It provides an http relation runs a Go HTTP handler as a service.
func (*Service) PublicHTTPSURL ¶
PublicHTTPSURL returns an http URL that can be used to access the HTTPS service, not including the trailing slash. It returns ErrHTTPSNotConfigured if there is no current https service.
func (*Service) PublicHTTPURL ¶
PublicHTTPURL returns a URL that can be used to access the HTTP service, not including the trailing slash. TODO https?
func (*Service) Register ¶
func (svc *Service) Register(r *hook.Registry, serviceName, relationName string, handler interface{})
Register registers the service with the given registry. If serviceName is non-empty, it specifies the name of the service, otherwise the service will be named after the charm's unit. The relationName parameter specifies the name of the http relation.
The handler value must be a function of the form:
func(T) (http.Handler, error)
for some type T that can be marshaled as JSON. When the service is started, this function will be called with the arguments provided to the Start method.
Note that the handler function will not be called with any hook context available, as it is run by the OS-provided service runner (e.g. upstart).
func (*Service) Start ¶
Start starts the service with the given argument. The type of arg must be the same as the type T in the handler function provided to Register.
If the argument values change, the service will be be restarted, otherwise the service will be left unchanged if it is already started.