control

package
v1.6.8 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package control provides atomic flag registries and helpers for job state and security flags.

Package control defines the stages of log entry processing.

Package control - job state machine baseada em bitflags para uso interno no pipeline do logger / manager.

Index

Constants

View Source
const (
	StepValidate ctl.JobFlag = 1 << iota
	StepPreHooks
	StepFormat
	StepPostHooks
	StepWrite
	StepDone
	StepFailed
)
View Source
const (
	StepTerminal = StepDone | StepFailed
)

Variables

This section is empty.

Functions

This section is empty.

Types

type FlagReg32

type FlagReg32[T ~uint32] struct {
	// contains filtered or unexported fields
}

FlagReg32 é um registrador genérico baseado em uint32 com operações atômicas para trabalhar com bitflags (T deve ser ~uint32).

func NewFlagReg32

func NewFlagReg32[T ~uint32]() *FlagReg32[T]

NewFlagReg32 cria um registrador novo, com valor inicial 0.

func (*FlagReg32[T]) All

func (r *FlagReg32[T]) All(mask T) bool

All é alias semântico pra Has.

func (*FlagReg32[T]) Any

func (r *FlagReg32[T]) Any(mask T) bool

Any retorna true se QUALQUER bit de mask estiver presente.

func (*FlagReg32[T]) Clear

func (r *FlagReg32[T]) Clear(mask T)

Clear faz AND-NOT bitwise com a máscara, de forma atômica.

func (*FlagReg32[T]) CompareAndSwap

func (r *FlagReg32[T]) CompareAndSwap(old, new T) bool

CompareAndSwap executa um CAS no valor inteiro do registrador.

func (*FlagReg32[T]) Has

func (r *FlagReg32[T]) Has(mask T) bool

Has retorna true se TODOS os bits de mask estiverem presentes.

func (*FlagReg32[T]) Load

func (r *FlagReg32[T]) Load() T

Load lê o valor atual do registrador.

func (*FlagReg32[T]) Set

func (r *FlagReg32[T]) Set(mask T)

Set faz OR bitwise com a máscara, de forma atômica.

func (*FlagReg32[T]) Store

func (r *FlagReg32[T]) Store(val T)

Store grava o valor bruto no registrador (cuidado: sobrescreve tudo).

type FlagReg32A

type FlagReg32A[T ~uint32] = FlagReg32[T]

Alias de compatibilidade: se em algum lugar você usou FlagReg32A/ NewFlagReg32A, continua funcionando sem quebrar nada.

func NewFlagReg32A

func NewFlagReg32A[T ~uint32]() *FlagReg32A[T]

type JobFlag

type JobFlag uint32
const (
	JobPendingA JobFlag = 1 << iota
	JobRunningA
	JobCancelRequestedA
	JobRetryingA
	JobCompletedA
	JobFailedA
	JobTimedOutA
)

func (JobFlag) Has

func (j JobFlag) Has(flag JobFlag) bool

type JobState

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

JobState encapsula a evolução do job via bitflags, usando FlagReg32[JobFlag].

func NewJobState

func NewJobState() *JobState

NewJobState cria um JobState novo, iniciando em zero (sem flags).

func (*JobState) Complete

func (s *JobState) Complete() error

Complete: marca Completed e limpa Running/Retrying/CancelRequested. Se já terminal, retorna ErrTerminal.

func (*JobState) Fail

func (s *JobState) Fail() error

Fail: marca Failed e limpa Running/Retrying, se ainda não terminal.

func (*JobState) IsTerminal

func (s *JobState) IsTerminal() bool

IsTerminal retorna true se o job já atingiu um estado terminal (Completed, Failed ou TimedOut).

func (*JobState) Load

func (s *JobState) Load() JobFlag

Load retorna os flags atuais.

func (*JobState) RequestCancel

func (s *JobState) RequestCancel()

RequestCancel seta o flag de cancelamento solicitado.

func (*JobState) Retry

func (s *JobState) Retry() error

Retry: marca Retry e limpa Running, se ainda não terminal.

func (*JobState) Start

func (s *JobState) Start() error

Start: permite transicionar para Running se não estiver em estado terminal. Se já estiver terminal, retorna ErrTerminal.

func (*JobState) Timeout

func (s *JobState) Timeout() error

Timeout: marca TimedOut e limpa Running/Retrying, se ainda não terminal.

type ManagerControl

type ManagerControl struct {
	Stage ManagerState
	State ManagerState
}

func NewManagerControl

func NewManagerControl() *ManagerControl

type ManagerState

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

func (*ManagerState) All

func (r *ManagerState) All(mask ctl.JobFlag) bool

func (*ManagerState) Any

func (r *ManagerState) Any(mask ctl.JobFlag) bool

func (*ManagerState) Clear

func (r *ManagerState) Clear(mask ctl.JobFlag)

func (*ManagerState) Load

func (r *ManagerState) Load() ctl.JobFlag

func (*ManagerState) Set

func (r *ManagerState) Set(mask ctl.JobFlag)

func (*ManagerState) SetIf

func (r *ManagerState) SetIf(clearMask, setMask ctl.JobFlag) bool

func (*ManagerState) Store

func (r *ManagerState) Store(val ctl.JobFlag)

type SecFlag

type SecFlag uint32

SecFlag representa opções de segurança aplicáveis a uma rota, handler, etc.

const (
	SecNone         SecFlag = 0
	SecAuth         SecFlag = 1 << iota // autenticação/autorização
	SecSanitize                         // sanitize em params/headers
	SecSanitizeBody                     // sanitize no body
)

func FromLegacyMap

func FromLegacyMap(m map[string]bool) SecFlag

FromLegacyMap converte mapa legado (ex: de config JSON) para flags. Mantém compat com chaves antigas: "validateAndSanitize", "validateAndSanitizeBody".

func (SecFlag) Has

func (f SecFlag) Has(mask SecFlag) bool

Has retorna true se TODOS os bits de mask estiverem presentes.

func (SecFlag) String

func (f SecFlag) String() string

String retorna uma representação textual dos flags ativos. Ex: "auth|sanitize_body" ou "none" se não houver nenhum setado.

func (SecFlag) With

func (f SecFlag) With(mask SecFlag) SecFlag

With adiciona um ou mais flags.

func (SecFlag) Without

func (f SecFlag) Without(mask SecFlag) SecFlag

Without remove um ou mais flags.

type StageReg32

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

func NewStageReg32

func NewStageReg32() *StageReg32

Jump to

Keyboard shortcuts

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