userserver

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Sep 4, 2025 License: MIT Imports: 6 Imported by: 0

README

github.com/faroedev/go-user-server

Package for building Faroe user servers.

package main

import "github.com/faroedev/go-user-server"

func handleRequest(w http.ResponseWriter, r *http.Request) {
    // actions implement faroe.ActionsInterface.
    var server = userserver.NewServer(actions)
    
    bodyJSONBytes, err := io.ReadAll(r.Body)
    if err != nil {
        w.WriteHeader(http.StatusBadRequest)
        return
    }

    resultJSON, err := resolver.ResolveActionInvocationEndpointRequest(string(bodyJSONBytes))
    if err != nil {
        w.WriteHeader(http.StatusBadRequest)
        return
    }

    w.Header().Set("Content-Type", "application/json")
    w.Write([]byte(resultJSON))
}

Documentation

Index

Constants

View Source
const (
	ActionCreateUser                   = "create_user"
	ActionGetUser                      = "get_user"
	ActionGetUserByEmailAddress        = "get_user_by_email_address"
	ActionUpdateUserEmailAddress       = "update_user_email_address"
	ActionUpdateUserPasswordHash       = "update_user_password_hash"
	ActionIncrementUserSessionsCounter = "increment_user_sessions_counter"
	ActionDeleteUser                   = "delete_user"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ActionErrorStruct

type ActionErrorStruct struct {
	ErrorCode string
}

Represents an action error. Use NewActionError.

func NewActionError

func NewActionError(errorCode string) *ActionErrorStruct

func (*ActionErrorStruct) Error

func (actionError *ActionErrorStruct) Error() string

type ActionsInterface

type ActionsInterface interface {
	// create_user action where the action parameters are mapped as:
	// 	- action_invocation_id: actionInvocationId
	// 	- email_address: emailAddress
	// 	- password_hash: passwordHash
	// 	- password_hash_algorithm_id: passwordHashAlgorithmId
	// 	- password_salt: passwordSalt
	// Returns the user return value.
	// If there is an error, it will always be [*ActionErrorStruct] with the action error code.
	CreateUserAction(actionInvocationId string, emailAddress string, passwordHash []byte, passwordHashAlgorithmId string, passwordSalt []byte) (UserStruct, error)

	// get_user action where the action parameters are mapped as:
	// 	- action_invocation_id: actionInvocationId
	// 	- user_id: userId
	// Returns the user return value.
	// If there is an error, it will always be [*ActionErrorStruct] with the action error code.
	GetUserAction(actionInvocationId string, userId string) (UserStruct, error)

	// get_user_by_email_address action where the action parameters are mapped as:
	// 	- action_invocation_id: actionInvocationId
	// 	- user_id: userId
	// Returns the user return value.
	// If there is an error, it will always be [*ActionErrorStruct] with the action error code.
	GetUserByEmailAddressAction(actionInvocationId string, emailAddress string) (UserStruct, error)

	// update_user_email_address action where the action parameters are mapped as:
	// 	- action_invocation_id: actionInvocationId
	// 	- user_id: userId
	// 	- email_address: emailAddress
	// 	- user_email_address_counter: userEmailAddressCounter
	// If there is an error, it will always be [*ActionErrorStruct] with the action error code.
	UpdateUserEmailAddressAction(actionInvocationId string, userId string, emailAddress string, userEmailAddressCounter int32) error

	// update_user_password_hash action where the action parameters are mapped as:
	// 	- action_invocation_id: actionInvocationId
	// 	- user_id: userId
	// 	- password_hash: passwordHash
	// 	- password_hash_algorithm_id: passwordHashAlgorithmId
	// 	- password_salt: passwordSalt
	// 	- user_password_hash_counter: userPasswordHashCounter
	// If there is an error, it will always be [*ActionErrorStruct] with the action error code.
	UpdateUserPasswordHashAction(actionInvocationId string, userId string, passwordHash []byte, passwordHashAlgorithmId string, passwordSalt []byte, userPasswordHashCounter int32) error

	// increment_user_sessions_counter action where the action parameters are mapped as:
	// 	- action_invocation_id: actionInvocationId
	// 	- user_id: userId
	// 	- user_sessions_counter: userSessionsCounter
	// If there is an error, it will always be [*ActionErrorStruct] with the action error code.
	IncrementUserSessionsCounterAction(actionInvocationId string, userId string, userSessionsCounter int32) error

	// delete_user action where the action parameters are mapped as:
	// 	- action_invocation_id: actionInvocationId
	// 	- user_id: userId
	// If there is an error, it will always be [*ActionErrorStruct] with the action error code.
	DeleteUserAction(actionInvocationId string, userId string) error
}

type ServerStruct

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

Use NewServer.

func NewServer

func NewServer(actions ActionsInterface) *ServerStruct

func (*ServerStruct) ResolveActionInvocationEndpointRequest

func (server *ServerStruct) ResolveActionInvocationEndpointRequest(bodyJSON string) (string, error)

Resolves an action invocation endpoint request. Returns the string body of a 200 response or an error if the request is invalid.

type UserStruct

type UserStruct struct {
	// Maps to id attribute.
	Id string

	// Maps to email_address attribute.
	EmailAddress string

	// Maps to password_hash attribute.
	PasswordHash []byte

	// Maps to password_hash attribute.
	PasswordHashAlgorithmId string

	// Maps to password_salt attribute.
	PasswordSalt []byte

	// Maps to disabled attribute.
	Disabled bool

	// Maps to display_name attribute.
	DisplayName string

	// Maps to email_address_counter attribute.
	EmailAddressCounter int32

	// Maps to password_hash_counter attribute.
	PasswordHashCounter int32

	// Maps to disabled_counter attribute.
	DisabledCounter int32

	// Maps to sessions_counter attribute.
	SessionsCounter int32
}

Jump to

Keyboard shortcuts

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