config

package
v0.0.0-...-3c57cc3 Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2025 License: GPL-3.0 Imports: 15 Imported by: 0

Documentation

Overview

Copyright © 2025 Rangertaha <rangertaha@gmail.com>

Copyright © 2025 Rangertaha <rangertaha@gmail.com>

Copyright © 2025 Rangertaha <rangertaha@gmail.com>

Copyright © 2025 Rangertaha <rangertaha@gmail.com>

Index

Constants

View Source
const (
	DefaultName = "ares-client"
	ClientURL   = nats.DefaultURL
	NomadURL    = ""
)
View Source
const (
	CONFIG_FILENAME = "config.hcl"
	DefaultSubject  = "ares.cmd"
)
View Source
const (
	KVTypeString = "string"
	KVTypeInt    = "int"
	KVTypeFloat  = "float"
	KVTypeBool   = "bool"
)
View Source
const YYYYMMDD = "2006/01/02"

Variables

View Source
var CtxFunctions *hcl.EvalContext = &hcl.EvalContext{
	Functions: map[string]function.Function{
		"seconds": SecondsFunc,
		"minutes": MinutesFunc,
		"hours":   HoursFunc,
		"days":    DaysFunc,
		"date":    DateFunc,
	},
}
View Source
var DateFunc = function.New(&function.Spec{
	Description: "Returns a date in int64 format",
	Params: []function.Parameter{
		{
			Name:             "date",
			Type:             cty.String,
			AllowDynamicType: true,
		},
	},
	Type: function.StaticReturnType(cty.Number),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		var date string
		if err := gocty.FromCtyValue(args[0], &date); err != nil {
			return cty.UnknownVal(cty.String), err
		}

		t, err := time.Parse(YYYYMMDD, date)
		if err != nil {
			return cty.UnknownVal(cty.String), err
		}

		return cty.NumberIntVal(t.Unix()), nil
	},
})
View Source
var DaysFunc = function.New(&function.Spec{
	Description: "Returns the given hours",
	Params: []function.Parameter{
		{
			Name:             "num",
			Type:             cty.Number,
			AllowDynamicType: true,
		},
	},
	Type: function.StaticReturnType(cty.Number),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		var days int64
		if err := gocty.FromCtyValue(args[0], &days); err != nil {
			return cty.UnknownVal(cty.String), err
		}

		return cty.NumberIntVal(int64(time.Duration(days) * (time.Hour * 24))), nil
	},
})
View Source
var (
	//go:embed config.hcl
	DefaultConfigBytes []byte
)
View Source
var HoursFunc = function.New(&function.Spec{
	Description: "Returns the given hours",
	Params: []function.Parameter{
		{
			Name:             "num",
			Type:             cty.Number,
			AllowDynamicType: true,
		},
	},
	Type: function.StaticReturnType(cty.Number),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		var hours int64
		if err := gocty.FromCtyValue(args[0], &hours); err != nil {
			return cty.UnknownVal(cty.String), err
		}

		return cty.NumberIntVal(int64(time.Duration(hours) * time.Hour)), nil
	},
})
View Source
var MinutesFunc = function.New(&function.Spec{
	Description: "Returns the given minutes",
	Params: []function.Parameter{
		{
			Name:             "num",
			Type:             cty.Number,
			AllowDynamicType: true,
		},
	},
	Type: function.StaticReturnType(cty.Number),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		var minutes int64
		if err := gocty.FromCtyValue(args[0], &minutes); err != nil {
			return cty.UnknownVal(cty.String), err
		}

		return cty.NumberIntVal(int64(time.Duration(minutes) * time.Minute)), nil
	},
})
View Source
var SecondsFunc = function.New(&function.Spec{
	Description: "Returns the given seconds",
	Params: []function.Parameter{
		{
			Name:             "num",
			Type:             cty.Number,
			AllowDynamicType: true,
		},
	},
	Type: function.StaticReturnType(cty.Number),
	Impl: func(args []cty.Value, retType cty.Type) (cty.Value, error) {
		var seconds int64
		if err := gocty.FromCtyValue(args[0], &seconds); err != nil {
			return cty.UnknownVal(cty.String), err
		}

		return cty.NumberIntVal(int64(time.Duration(seconds) * time.Second)), nil
	},
})

Functions

func DefaultConfig

func DefaultConfig() func(*Config) error

func FileOption

func FileOption(cFile string) func(*Config) error

func GetOrCreateConfigFile

func GetOrCreateConfigFile(filename string, defaultContent []byte) (string, error)

Types

type Broker

type Broker struct {
	Name string `hcl:"name,label"`
	Host string `hcl:"addr,optional"`
	Port int    `hcl:"port,optional"`
	// DontListen            bool   `hcl:"dont_listen"`
	// ClientAdvertise       string `hcl:",optional"`
	// Trace                 bool   `hcl:",optional"`
	Debug bool `hcl:"debug,optional"`
}

func (*Broker) Options

func (s *Broker) Options() *server.Options

type ClusterOpts

type ClusterOpts struct{}

type Config

type Config struct {
	Debug   bool   `hcl:"debug,optional"`
	Version string `hcl:"version,optional"`
	Tags    Tags   `hcl:"tags,optional"`

	Broker *Broker `hcl:"broker,block"`
}

func New

func New(options ...func(*Config) error) (*Config, error)

New creates a new configuration

func (*Config) Update

func (c *Config) Update(options ...func(*Config) error) error

type Credentials

type Credentials struct {
	ID        int        `hcl:"id,optional"`
	Provider  string     `hcl:"provider,optional"`
	KeyValues []KeyValue `hcl:"settings,optional"`
}

type KeyValue

type KeyValue struct {
	Key   string      `hcl:"key"`
	Value interface{} `hcl:"value"`
	Type  string      `hcl:"type"`
}

type Plugin

type Plugin struct {
	Id      string `hcl:"name,label"`
	Summary string `hcl:"summary,optional"`

	// Timing
	Interval   time.Duration `hcl:"interval,optional"`
	Resolution time.Duration `hcl:"resolusion,optional"`
	Precision  time.Duration `hcl:"precision,optional"`
	Window     time.Duration `hcl:"window,optional"`

	Tags      Tags          `hcl:"tags,optional"`
	Creds     []Credentials `hcl:"credentials,optional"`
	KeyValues []KeyValue    `hcl:"settings,optional"`
}

type Tags

type Tags map[string]string

Jump to

Keyboard shortcuts

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