config

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2022 License: GPL-3.0 Imports: 6 Imported by: 0

README

Config Parser

Config Parser is a simple library for parsing configuration files in order to support the handler.

Documentation

Index

Constants

View Source
const (
	WILL_FIT   uint8 = iota // debug level
	SHOULD_FIT              // info
	MAY_FIT                 // warning
	WONT_FIT                // fatal
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Action

type Action struct {
	Action ActionType `json:"action"`  // Type of action to take when the rule is matched
	ToAddr string     `json:"to_addr"` // Address to FORWARD to, if type is FORWARD
}

Action is a struct representing an action to be taken on a request that matches a rule

type ActionType

type ActionType uint8
const (
	ACTION_REJECT  ActionType = iota // "REJECT" - 0
	ACTION_FORWARD                   // "FORWARD" - 1
)

func (*ActionType) MarshalJSON

func (at *ActionType) MarshalJSON() ([]byte, error)

func (*ActionType) UnmarshalJSON

func (at *ActionType) UnmarshalJSON(data []byte) error

type Config

type Config struct {
	Version Version     `json:"version"`
	Servers ServerGroup `json:"servers"` // A list of servers to listen on
}

Config is a struct that can be loaded from a JSON file or written to a JSON file

func LoadConfig

func LoadConfig(filename string) (*Config, error)

func (*Config) Write

func (c *Config) Write(filename string) error

type Filter

type Filter = map[Rule]Action

Filter defines the Rule to Action mapping relationship.

type Protocol

type Protocol = string // E.g.: "TLS", "SSH"

Protocol is a string representing the protocol name

type ProtocolGroup

type ProtocolGroup = map[Protocol]Filter

ProtocolGroup includes filters to apply to the request per each protocol

type Rule

type Rule = string // E.g.: "SNI example.com", "CATCHALL"

Rule is a string that can be matched against a request by a filter

type ServerAddr

type ServerAddr = string

type ServerGroup

type ServerGroup = map[ServerAddr]ProtocolGroup

ServerGroup is a map of server address to protocol filters

type Version

type Version struct {
	Major int
	Minor int
	Patch int
}

Version is a struct that represents the version of the config file v1.2.3 would be represented as:

Version{
	Major: 1,
	Minor: 2,
	Patch: 3,
}

func (*Version) CanFitInServer

func (v *Version) CanFitInServer(serverVer *Version) uint8

func (*Version) MarshalJSON

func (v *Version) MarshalJSON() ([]byte, error)

func (*Version) UnmarshalJSON

func (v *Version) UnmarshalJSON(data []byte) error

Jump to

Keyboard shortcuts

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