cfg

package module
v0.0.0-...-bac1ffb Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2024 License: MIT Imports: 7 Imported by: 4

README

config

General configuration library for applications

MIT License

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNoDataFromSource = errors.New(`no data from source for configuration`)
	ErrSaveNotLocalFile = errors.New("configuration file is not local")
)

Functions

This section is empty.

Types

type APIKeyInfo

type APIKeyInfo struct {
	ID    string
	Name  string
	Key   string
	Token *string
}

APIKeyInfo contains an API info

type CacheInfo

type CacheInfo struct {
	Provider string
	Address  string
	Password string
	DB       int
}

CacheInfo connection information

type Configuration

type Configuration struct {
	APIEndpoints          *[]EndpointInfo     `json:"APIEndpoints,omitempty"`          // External API endpoints that this application can communicate
	APIKeys               *[]APIKeyInfo       `json:"APIKeys,omitempty"`               // API Keys
	ApplicationID         *string             `json:"ApplicationID,omitempty"`         // ID of this application
	ApplicationName       *string             `json:"ApplicationName,omitempty"`       // Name of this application
	ApplicationTheme      *string             `json:"ApplicationTheme,omitempty"`      // Theme of this application
	Cache                 *CacheInfo          `json:"Cache,omitempty"`                 // Cache info of this application
	CertificateFile       *string             `json:"CertificateFile,omitempty"`       // Certificate file
	CertificateKey        *string             `json:"CertificateKey,omitempty"`        // Certificate private key
	CookieDomain          *string             `json:"CookieDomain,omitempty"`          // The domain of the cookie that this application will send
	CrossOriginDomains    *[]string           `json:"CrossOriginDomains,omitempty"`    // Domains or endpoints that this application will allow
	Databases             *[]DatabaseInfo     `json:"Databases,omitempty"`             // Configured databases for this application use
	Directories           *[]DirectoryInfo    `json:"Directories,omitempty"`           // Configured directory for this application use
	DefaultDatabaseID     *string             `json:"DefaultDatabaseID,omitempty"`     // The default database id that this application will find on the database configuration
	DefaultEndpointID     *string             `json:"DefaultEndpointID,omitempty"`     // The default endpoint that this application will find on the API endpoints configuration
	DefaultNotificationID *string             `json:"DefaultNotificationID,omitempty"` // The default notification id that this application will find on the notification configuration
	Domains               *[]DomainInfo       `json:"Domains,omitempty"`               // Configured domains for this application use
	FileName              string              `json:"FileName,omitempty"`              // Filename of the current configuration
	Flags                 *[]Flag             `json:"Flags,omitempty"`                 // Miscellaneous flags for this application use
	HostInternalURL       *string             `json:"HostInternalURL,omitempty"`       // The internal host URL that this application will use to set returned resources and assets
	HostExternalURL       *string             `json:"HostExternalURL,omitempty"`       // The external host URL that this application will use to set returned resources and assets
	HostPort              *int                `json:"HostPort,omitempty"`              // The network port for the application
	JWTSecret             *string             `json:"JWTSecret,omitempty"`             // Application wide JSON Web Token (JWT) secret
	LicenseSerial         *string             `json:"LicenseSerial,omitempty"`         // License serial of this application
	Notifications         *[]NotificationInfo `json:"Notifications,omitempty"`         // Configured notifications for this application use
	Queue                 *QueueInfo          `json:"Queue,omitempty"`                 // Queue or message queue
	ReadTimeout           *int                `json:"ReadTimeout,omitempty"`           // Default network timeout setting for reading data uploaded to this application
	Secure                *bool               `json:"Secure,omitempty"`                // Flags if secure
	Sources               *[]SourceInfo       `json:"Sources,omitempty"`               // Folder sources
	WriteTimeout          *int                `json:"WriteTimeout,omitempty"`          // Default network timeout setting for writing data downloaded from this application
	// contains filtered or unexported fields
}

Configuration - for various configuration settings. This struct can be modified depending on the requirement.

func Load

func Load(source string) (*Configuration, error)

Load loads configuration file and return a configuration

func (*Configuration) Flag

func (c *Configuration) Flag(key string) Flag

Flag gets a flag value

func (*Configuration) GetDatabaseInfo

func (c *Configuration) GetDatabaseInfo(connectionId string) *DatabaseInfo

GetDatabaseInfo get a database info by its ID

func (*Configuration) GetDatabaseInfoGroup

func (c *Configuration) GetDatabaseInfoGroup(groupId string) []DatabaseInfo

GetDatabaseInfoGroup gets database infos based on the group id

func (*Configuration) GetDirectory

func (c *Configuration) GetDirectory(groupId string) *DirectoryInfo

GetDirectory retrieves a directory under a group

func (*Configuration) GetDirectoryItem

func (c *Configuration) GetDirectoryItem(groupId, key string) *Flag

GetDirectoryItem retrieves a directory item under a group

func (*Configuration) GetDomainInfo

func (c *Configuration) GetDomainInfo(domainName string) *DomainInfo

GetDomainInfo gets a domain info by name

func (*Configuration) GetEndpointAddress

func (c *Configuration) GetEndpointAddress(id ...string) string

GetEndpointAddress gets an endpoint address value

func (*Configuration) GetEndpointInfo

func (c *Configuration) GetEndpointInfo(id ...string) *EndpointInfo

GetEndpointInfo - get an endpoint by id

func (*Configuration) GetEndpointInfoGroup

func (c *Configuration) GetEndpointInfoGroup(groupId string) []EndpointInfo

GetDatabaseInfoGroup gets database infos based on the group id

func (*Configuration) GetNotificationInfo

func (c *Configuration) GetNotificationInfo(id ...string) *NotificationInfo

GetNotificationInfo gets notification info

func (*Configuration) GetSourceInfo

func (c *Configuration) GetSourceInfo(sourceId string) *SourceInfo

GetSourceInfo gets source by id

func (*Configuration) Reload

func (c *Configuration) Reload() error

Reload configuration

func (*Configuration) Save

func (c *Configuration) Save() error

Save saves configuration file

type DatabaseInfo

type DatabaseInfo struct {
	GroupID                *string                `json:"GroupID,omitempty"`                // GroupID allows us to get groups of connection
	ID                     string                 `json:"ID,omitempty"`                     // A unique ID that will identify the connection to a database
	ConnectionString       string                 `json:"ConnectionString,omitempty"`       // ConnectionString specific to the database
	DriverName             string                 `json:"DriverName,omitempty"`             // DriverName needs to be specified depending on the driver id used by the Go database driver
	StorageType            string                 `json:"StorageType,omitempty"`            // FILE for filebased database such as Access, SQlite or LocalDB. SERVER for SQL Server, MySQL etc
	HelperID               string                 `json:"HelperID,omitempty"`               // When using github.com/NarsilWorks-Inc/datahelperlite, this is needed in the configuration file
	ParameterPlaceholder   string                 `json:"ParameterPlaceholder,omitempty"`   // Parameter place holder for prepared statements. Default is '?'
	ParameterInSequence    bool                   `json:"ParameterInSequence,omitempty"`    // Parameter place holder is in sequence. Default is false
	Schema                 string                 `json:"Schema,omitempty"`                 // Schema for any of the database operations
	InterpolateTables      *bool                  `json:"InterpolateTables,omitempty"`      // Enables the tables to be interpolated with schema
	SequenceGenerator      *SequenceGeneratorInfo `json:"SequenceGenerator,omitempty"`      // Sequence generator configuration
	StringEnclosingChar    *string                `json:"StringEnclosingChar,omitempty"`    // Gets or sets the character that encloses a string in the query
	StringEscapeChar       *string                `json:"StringEscapeChar,omitempty"`       // Gets or Sets the character that escapes a reserved character such as the character that encloses a s string
	IdentityQuery          *string                `json:"IdentityQuery,omitempty"`          // A query to get the generated identity
	DateFunction           *string                `json:"DateFunction,omitempty"`           // The date function of each SQL database driver
	UTCDateFunction        *string                `json:"UTCDateFunction,omitempty"`        // The UTC date function of each SQL database driver
	MaxOpenConnection      *int                   `json:"MaxOpenConnection,omitempty"`      // Maximum open connection
	MaxIdleConnection      *int                   `json:"MaxIdleConnection,omitempty"`      // Maximum idle connection
	MaxConnectionLifetime  *int                   `json:"MaxConnectionLifetime,omitempty"`  // Max connection lifetime
	MaxConnectionIdleTime  *int                   `json:"MaxConnectionIdleTime,omitempty"`  // Max idle connection lifetime
	Ping                   *bool                  `json:"Ping,omitempty"`                   // Ping connection
	ReservedWordEscapeChar *string                `json:"ReservedWordEscapeChar,omitempty"` // Reserved word escape chars. For escaping with different opening and closing characters, just set to both. Example. `[]` for SQL server
	KeywordMap             *[]DatabaseKeyword     `json:"KeywordMap,omitempty"`             // various keyword equivalents
}

DatabaseInfo - database configuration setting

type DatabaseKeyword

type DatabaseKeyword struct {
	Flag
}

DatabaseKeyword - struct for database keywords

type DirectoryInfo

type DirectoryInfo struct {
	GroupID     string
	Description string
	Items       []Flag
}

DirectoryInfo contains a directory info

type DomainInfo

type DomainInfo struct {
	Name               string
	Host               string
	Port               uint16
	Path               string
	AuthorizedUser     string
	AuthorizedPassword string
	Filter             string
}

DomainInfo - domain information for LDAP authentication

type EndpointInfo

type EndpointInfo struct {
	ID      string  // Endpoint ID for quick access
	Name    string  // Endpoint Name to show
	Address string  // The absolute URL to the resource
	GroupID *string // A group id to get certain endpoint set
	Token   *string
}

Endpoint - endpoint struct

type Flag

type Flag struct {
	Key   string  `json:"key,omitempty"`
	Value *string `json:"value,omitempty"`
}

Flag - dynamic flags structure

func (Flag) Bool

func (f Flag) Bool() *bool

Bool - return a boolean from flag value

func (Flag) Float

func (f Flag) Float() *float32

Float - return an float from flag value

func (Flag) Float64

func (f Flag) Float64() *float64

Float - return an float from flag value

func (Flag) Int

func (f Flag) Int() *int

Int - return an int from flag value

func (Flag) Int64

func (f Flag) Int64() *int64

Int64 - return an int64 from flag value

func (Flag) String

func (f Flag) String() *string

String - return a string from flag value

type NotificationInfo

type NotificationInfo struct {
	ID            string
	APIHost       string
	APIPath       string
	Type          string
	Login         string
	Password      string
	Active        bool
	SenderAddress string
	SenderName    string
	ReplyTo       string
	Recipients    []NotificationRecipient
}

NotificationInfo - notification information on connecting to Notify API

type NotificationRecipient

type NotificationRecipient struct {
	ID      string
	Name    string
	Address string
}

NotificationRecipient - notification standard recipients

type QueueInfo

type QueueInfo struct {
	ID                 string   `json:"ID,omitempty"`                 // ID of the setting
	ServerAddressGroup []string `json:"ServerAddressGroup,omitempty"` // Queue server address group
	Cluster            string   `json:"Cluster,omitempty"`            // Cluster name
	ClientID           string   `json:"ClientID,omitempty"`           // ClientID of the service
	StreamName         string   `json:"StreamName,omitempty"`         // Stream name
}

QueueInfo - queue info connector

type SequenceGeneratorInfo

type SequenceGeneratorInfo struct {
	UpsertQuery     string
	ResultQuery     string
	NamePlaceHolder string
}

SequenceGeneratorInfo - sequence generator query

type SourceInfo

type SourceInfo struct {
	ID        string `json:"id,omitempty"`        // ID of the source for quick reference
	Type      string `json:"type,omitempty"`      // Type of Inbound file. Supported types are ORDER and SNAPSHOT
	Source    string `json:"source,omitempty"`    // Source folder of the source
	Relative  bool   `json:"relative"`            // Indicates that the Error and Success folders are relative to Source
	Error     string `json:"error,omitempty"`     // Error folder of the source
	Success   string `json:"success,omitempty"`   // Success folder of the source
	Extension string `json:"extension,omitempty"` // Extension of the file to pickup
}

SourceInfo - file sources for configuration

Jump to

Keyboard shortcuts

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