reason

package
v0.0.0-...-a54a33a Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2020 License: AGPL-3.0 Imports: 5 Imported by: 5

Documentation

Overview

Package reason provides some utils for encoding data into a 'reason' string.

This package is a work in progress and makes no API stability promises.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Clean

func Clean(reason string) string

Clean removes policy and other stuff from a reason string

func ExtractScore

func ExtractScore(s string) (int, string, error)

ExtractScore extracts a score from a reason string. It returns the score, an string reason without the score and error

func WithPolicy

func WithPolicy(policy Policy, s string) string

WithPolicy inserts a policy inside a reason string. If there is a policy inside, WithPolicy will replace it.

func WithScore

func WithScore(score int, s string) string

WithScore inserts a score inside a reason string. If there is a score inside, WithScore will replace it.

Types

type Policy

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

Policy stores fields and values (both are strings). Warning, it's unsafe.

func ExtractPolicy

func ExtractPolicy(s string) (Policy, string, error)

ExtractPolicy extracts a policy from a reason string. It returns the policy, an string reason without the policy and error.

func NewPolicy

func NewPolicy() Policy

NewPolicy returns a new policy.

func (Policy) Empty

func (p Policy) Empty() bool

Empty returns true if the policy is empty.

func (Policy) Fields

func (p Policy) Fields() []string

Fields returns the fields in the policy.

func (*Policy) FromString

func (p *Policy) FromString(s string) error

FromString loads from a encoded string the values of a policy. String must be in the format:

[policy]field1=value1,field2=value2[/policy]

func (Policy) Get

func (p Policy) Get(field string) (string, bool)

Get returns the value of the field.

func (Policy) Merge

func (p Policy) Merge(policies ...Policy)

Merge policies.

func (Policy) Set

func (p Policy) Set(field, value string) error

Set a new field policy or modify existing value.

func (Policy) String

func (p Policy) String() string

String returns the policy encoded as string.

Jump to

Keyboard shortcuts

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