login

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: 15 Imported by: 0

Documentation

Overview

Package login implements the login.example microservice.

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.

View Source
const SourceCodeSHA256 = "c013a7622db07668083117aa9b1a1c63144b7701253ecd646bf22b56d3fb7792"
View Source
const Timestamp = "2025-11-29T02:31:02.051216Z"
View Source
const Version = 80

Variables

This section is empty.

Functions

This section is empty.

Types

type Actor

type Actor struct {
	Subject string   `json:"sub"`
	Roles   []string `json:"roles"`
}

Actor represents the authenticated user. It is parsed from the claims associated with the request.

func (Actor) HasRole

func (a Actor) HasRole(role string) bool

HasRole checks if the actor can claim the indicated role.

func (Actor) IsAdmin

func (a Actor) IsAdmin() bool

IsAdmin indicates if the actor can claim the admin role.

func (Actor) IsManager

func (a Actor) IsManager() bool

IsAdmin indicates if the can claim the manager role.

func (Actor) IsUser

func (a Actor) IsUser() bool

IsAdmin indicates if the actor can claim the user role.

func (*Actor) SetAdmin

func (a *Actor) SetAdmin()

SetAdmin claims the admin role for the actor.

func (*Actor) SetManager

func (a *Actor) SetManager()

SetManager claims the manager role for the actor.

func (*Actor) SetUser

func (a *Actor) SetUser()

SetUser claims the user role for the actor.

func (Actor) String

func (a Actor) String() string

String prints the actor as JSON.

type Mock

type Mock = intermediate.Mock

Mock is a mockable version of the login.example microservice, allowing functions, event sinks and web handlers to be mocked.

func NewMock

func NewMock() *Mock

New creates a new mockable version of the microservice.

type Service

type Service struct {
	*intermediate.Intermediate // DO NOT REMOVE
}

Service implements the login.example microservice.

The Login microservice demonstrates usage of authentication and authorization.

func NewService

func NewService() *Service

NewService creates a new login.example microservice.

func (*Service) AdminOnly

func (svc *Service) AdminOnly(w http.ResponseWriter, r *http.Request) (err error)

AdminOnly is only accessible by admins.

func (*Service) Init

func (svc *Service) Init(initializer func(svc *Service)) *Service

Init enables a single-statement pattern for initializing the microservice.

svc.Init(func(svc Service) {
	svc.SetGreeting("Hello")
})

func (*Service) Login

func (svc *Service) Login(w http.ResponseWriter, r *http.Request) (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".

func (*Service) Logout

func (svc *Service) Logout(w http.ResponseWriter, r *http.Request) (err error)

Logout renders a page that logs out the user.

func (*Service) ManagerOnly

func (svc *Service) ManagerOnly(w http.ResponseWriter, r *http.Request) (err error)

ManagerOnly is only accessible by managers.

func (*Service) OnShutdown

func (svc *Service) OnShutdown(ctx context.Context) (err error)

OnShutdown is called when the microservice is shut down.

func (*Service) OnStartup

func (svc *Service) OnStartup(ctx context.Context) (err error)

OnStartup is called when the microservice is started up.

func (*Service) Welcome

func (svc *Service) Welcome(w http.ResponseWriter, r *http.Request) (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.

Directories

Path Synopsis
Package intermediate serves as the foundation of the login.example microservice.
Package intermediate serves as the foundation of the login.example microservice.
Package loginapi implements the public API of the login.example microservice, including clients and data structures.
Package loginapi implements the public API of the login.example microservice, including clients and data structures.

Jump to

Keyboard shortcuts

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