loginapi

package
v1.20.1 Latest Latest
Warning

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

Go to latest
Published: Dec 10, 2025 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package loginapi implements the public API of the login.example microservice, including clients and data structures.

The Login microservice demonstrates usage of authentication and authorization.

Index

Constants

View Source
const Hostname = "login.example"

Hostname is the default hostname of the microservice: login.example.

Variables

View Source
var (
	URLOfLogin       = httpx.JoinHostAndPath(Hostname, `:443/login`)
	URLOfLogout      = httpx.JoinHostAndPath(Hostname, `:443/logout`)
	URLOfWelcome     = httpx.JoinHostAndPath(Hostname, `:443/welcome`)
	URLOfAdminOnly   = httpx.JoinHostAndPath(Hostname, `:443/admin-only`)
	URLOfManagerOnly = httpx.JoinHostAndPath(Hostname, `:443/manager-only`)
)

Fully-qualified URLs of the microservice's endpoints.

Functions

This section is empty.

Types

type Client

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

Client is a lightweight proxy for making unicast calls to the login.example microservice.

func NewClient

func NewClient(caller service.Publisher) Client

NewClient creates a new unicast client proxy to the login.example microservice.

func (Client) AdminOnly

func (_c Client) AdminOnly(ctx context.Context, relURL string) (res *http.Response, err error)

AdminOnly is only accessible by admins.

If a URL is provided, it is resolved relative to the URL of the endpoint.

func (Client) ForHost

func (_c Client) ForHost(host string) Client

ForHost returns a copy of the client with a different hostname to be applied to requests.

func (Client) Login

func (_c Client) Login(ctx context.Context, method string, relURL string, contentType string, body any) (res *http.Response, err error)

Login renders a simple login screen that authenticates a user. Known users are hardcoded as "admin", "manager" and "user". The password is "password".

If a URL is provided, it is resolved relative to the URL of the endpoint. If the body if of type io.Reader, []byte or string, it is serialized in binary form. If it is of type url.Values, it is serialized as form data. All other types are serialized as JSON. If a content type is not explicitly provided, an attempt will be made to derive it from the body.

func (Client) Logout

func (_c Client) Logout(ctx context.Context, method string, relURL string, contentType string, body any) (res *http.Response, err error)

Logout renders a page that logs out the user.

If a URL is provided, it is resolved relative to the URL of the endpoint. If the body if of type io.Reader, []byte or string, it is serialized in binary form. If it is of type url.Values, it is serialized as form data. All other types are serialized as JSON. If a content type is not explicitly provided, an attempt will be made to derive it from the body.

func (Client) ManagerOnly

func (_c Client) ManagerOnly(ctx context.Context, relURL string) (res *http.Response, err error)

ManagerOnly is only accessible by managers.

If a URL is provided, it is resolved relative to the URL of the endpoint.

func (Client) Welcome

func (_c Client) Welcome(ctx context.Context, method string, relURL string, contentType string, body any) (res *http.Response, err error)

Welcome renders a page that is shown to the user after a successful login. Rendering is adjusted based on the user's roles.

If a URL is provided, it is resolved relative to the URL of the endpoint. If the body if of type io.Reader, []byte or string, it is serialized in binary form. If it is of type url.Values, it is serialized as form data. All other types are serialized as JSON. If a content type is not explicitly provided, an attempt will be made to derive it from the body.

func (Client) WithOptions

func (_c Client) WithOptions(opts ...pub.Option) Client

WithOptions returns a copy of the client with options to be applied to requests.

type MulticastClient

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

MulticastClient is a lightweight proxy for making multicast calls to the login.example microservice.

func NewMulticastClient

func NewMulticastClient(caller service.Publisher) MulticastClient

NewMulticastClient creates a new multicast client proxy to the login.example microservice.

func (MulticastClient) AdminOnly

func (_c MulticastClient) AdminOnly(ctx context.Context, relURL string) <-chan *pub.Response

AdminOnly is only accessible by admins.

If a URL is provided, it is resolved relative to the URL of the endpoint.

func (MulticastClient) ForHost

func (_c MulticastClient) ForHost(host string) MulticastClient

ForHost returns a copy of the client with a different hostname to be applied to requests.

func (MulticastClient) Login

func (_c MulticastClient) Login(ctx context.Context, method string, relURL string, contentType string, body any) <-chan *pub.Response

Login renders a simple login screen that authenticates a user. Known users are hardcoded as "admin", "manager" and "user". The password is "password".

If a URL is provided, it is resolved relative to the URL of the endpoint. If the body if of type io.Reader, []byte or string, it is serialized in binary form. If it is of type url.Values, it is serialized as form data. All other types are serialized as JSON. If a content type is not explicitly provided, an attempt will be made to derive it from the body.

func (MulticastClient) Logout

func (_c MulticastClient) Logout(ctx context.Context, method string, relURL string, contentType string, body any) <-chan *pub.Response

Logout renders a page that logs out the user.

If a URL is provided, it is resolved relative to the URL of the endpoint. If the body if of type io.Reader, []byte or string, it is serialized in binary form. If it is of type url.Values, it is serialized as form data. All other types are serialized as JSON. If a content type is not explicitly provided, an attempt will be made to derive it from the body.

func (MulticastClient) ManagerOnly

func (_c MulticastClient) ManagerOnly(ctx context.Context, relURL string) <-chan *pub.Response

ManagerOnly is only accessible by managers.

If a URL is provided, it is resolved relative to the URL of the endpoint.

func (MulticastClient) Welcome

func (_c MulticastClient) Welcome(ctx context.Context, method string, relURL string, contentType string, body any) <-chan *pub.Response

Welcome renders a page that is shown to the user after a successful login. Rendering is adjusted based on the user's roles.

If a URL is provided, it is resolved relative to the URL of the endpoint. If the body if of type io.Reader, []byte or string, it is serialized in binary form. If it is of type url.Values, it is serialized as form data. All other types are serialized as JSON. If a content type is not explicitly provided, an attempt will be made to derive it from the body.

func (MulticastClient) WithOptions

func (_c MulticastClient) WithOptions(opts ...pub.Option) MulticastClient

WithOptions returns a copy of the client with options to be applied to requests.

Jump to

Keyboard shortcuts

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