configurations

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 25, 2023 License: MIT Imports: 14 Imported by: 4

Documentation

Index

Constants

View Source
const ApplicationConfigurationName = "application.codefly.yaml"
View Source
const ApplicationKind = "application"
View Source
const GlobalConfigurationName = "codefly.yaml"
View Source
const Grpc = "grpc"
View Source
const Http = "http"
View Source
const NetworkPrefix = "CODEFLY-NETWORK_"
View Source
const PluginFactoryService = "factory::service"
View Source
const PluginLibrary = "library"
View Source
const PluginRuntimeService = "runtime::service"
View Source
const PluginService = "service"
View Source
const ProjectConfigurationName = "project.codefly.yaml"
View Source
const RestFramework = "rest"
View Source
const ServiceConfigurationName = "service.codefly.yaml"
View Source
const Tcp = "tcp"
View Source
const Unknown = "unknown"

Variables

This section is empty.

Functions

func AddApplication

func AddApplication(app *ApplicationEntry) error

func AsEnvironmentVariable

func AsEnvironmentVariable(reference string, addresses []string) string

func ExistsAtDir

func ExistsAtDir[C Configuration](dir string) bool

func ExtendDomain

func ExtendDomain(domain string, extension string) string

func FindUp

func FindUp[C Configuration](cur string) (*C, error)

func GlobalConfigurationDir

func GlobalConfigurationDir() string

func GlobalProjectRoot

func GlobalProjectRoot() string

func HomeDir

func HomeDir() string

func InitGlobal

func InitGlobal(getter GlobalConfigurationInputer, override Override)

InitGlobal initializes the global configuration of codefly GlobalConfigurationInputer: setup the configuration and defaults Override: policy to replace existing configuration

func KnownPluginImplementationKinds

func KnownPluginImplementationKinds() []string

func KnownProjects

func KnownProjects() []string

func LoadFromDir

func LoadFromDir[C Configuration](dir string) (*C, error)

func LoadFromPath

func LoadFromPath[C Configuration](p string) (*C, error)

func LoadGlobalConfiguration

func LoadGlobalConfiguration()

func LoadSpec

func LoadSpec(content []byte, obj any, override shared.BaseLogger) error

func NewProject

func NewProject(builder ProjectBuilder) error

func OverrideWorkspaceConfigDir

func OverrideWorkspaceConfigDir(dir string)

func OverrideWorkspaceProjectRoot

func OverrideWorkspaceProjectRoot(dir string)

func ParseEnvironmentVariable

func ParseEnvironmentVariable(env string) (string, []string)

func ParseServiceInput

func ParseServiceInput(input string) (string, string, error)

func Path

func Path[C Configuration](dir string) string

func ProjectPath

func ProjectPath(relativePath string) string

func RelativeProjectPath

func RelativeProjectPath(p string) string

func Reset

func Reset()

func SaveCurrent

func SaveCurrent()

func SaveToDir

func SaveToDir[C Configuration](c *C, dir string) error

func SerializeAddresses

func SerializeAddresses(addresses []string) string

func SerializeSpec

func SerializeSpec(spec any) ([]byte, error)

func SetCurrentApplication

func SetCurrentApplication(app *Application)

func SetCurrentProject

func SetCurrentProject(p *Project)

func SolveDir

func SolveDir(dir string) string

func SolveDirOrCreate

func SolveDirOrCreate(dir string) string

func SupportedApi

func SupportedApi(kind string) error

func TypeName

func TypeName[C Configuration]() string

func ValidateDomain

func ValidateDomain()

func ValidateOrganization

func ValidateOrganization(org string) error

func ValidateProjectName

func ValidateProjectName(name string) error

func ValidateServiceName

func ValidateServiceName(name string) error

Types

type Api

type Api struct {
	Protocol  string `yaml:"protocol"`
	Framework string `yaml:"framework,omitempty"`
}

type ApiFramework

type ApiFramework string
const (
	GrpcApiFramework    ApiFramework = "grpc"
	RestApiFramework    ApiFramework = "rest"
	GraphQLApiFramework ApiFramework = "graphql"
)

type Application

type Application struct {
	Kind         string `yaml:"kind"`
	Name         string `yaml:"name"`
	RelativePath string `yaml:"relative-path"`
	Project      string `yaml:"project"`
	Domain       string `yaml:"domain"`

	Services []*ServiceReference `yaml:"services"`
}

func CurrentApplication

func CurrentApplication(opts ...Option) (*Application, error)

func FindApplicationUp

func FindApplicationUp(p string) (*Application, error)

func ListApplications

func ListApplications(opts ...Option) ([]*Application, error)

func LoadApplicationFromDir

func LoadApplicationFromDir(dir string) (*Application, error)

func LoadApplicationFromName

func LoadApplicationFromName(name string, opts ...Option) (*Application, error)

func MustCurrentApplication

func MustCurrentApplication() *Application

func NewApplication

func NewApplication(name string) (*Application, error)

func (*Application) AddService

func (app *Application) AddService(service *Service) error

func (*Application) Dir

func (app *Application) Dir(opts ...Option) string

func (*Application) GetServiceReferences

func (app *Application) GetServiceReferences(name string) (*ServiceReference, error)

func (*Application) Relative

func (app *Application) Relative(absolute string, opts ...Option) string

func (*Application) Save

func (app *Application) Save() error

func (*Application) ServiceDomain

func (app *Application) ServiceDomain(name string) string

func (*Application) Unique

func (app *Application) Unique() string

type ApplicationEntry

type ApplicationEntry struct {
	Name         string `yaml:"name"`
	RelativePath string `yaml:"relative-path"`
}

type ClientEntry

type ClientEntry struct {
	Name string   `yaml:"name"`
	Apis []string `yaml:"apis"`
}

func (*ClientEntry) Validate

func (c *ClientEntry) Validate() error

type Configuration

type Configuration interface {
}

type Endpoint

type Endpoint struct {
	Name        string `yaml:"name"`
	Description string `yaml:"description,omitempty"`
	// FailOver indicates that this endpoint should fail over to another endpoint
	FailOver *Endpoint `yaml:"fail-over,omitempty"`
}

type EndpointEntry

type EndpointEntry struct {
	Endpoint *Endpoint
	Api      *Api
}

type GlobalConfigurationInputer

type GlobalConfigurationInputer interface {
	// Fetch instantiates the input
	Fetch() error
	// Organization is now global
	Organization() string
	// Domain associated with the organization
	Domain() string
	// CreateDefaultProject returns true if a default project should be created
	CreateDefaultProject() bool
	// ProjectBuilder abstracts away the configuration of Project creation
	ProjectBuilder() ProjectBuilder
}

A GlobalConfigurationInputer abstracts away global configuration and default of project creation

type NoApplicationError

type NoApplicationError struct {
	Project string
}

func (NoApplicationError) Error

func (e NoApplicationError) Error() string

type Option

type Option func(scope *Scope)

func WithApplication

func WithApplication(app *Application) Option

func WithProject

func WithProject(project *Project) Option

type Override

type Override interface {
	Override(p string) bool
}

type Plugin

type Plugin struct {
	Kind       string `yaml:"kind"`
	Identifier string `yaml:"name"`
	Version    string `yaml:"version"`
	Publisher  string `yaml:"publisher"`
}

func NewPlugin

func NewPlugin(kind string, publisher string, identifier string, version string) *Plugin

func ParsePlugin

func ParsePlugin(kind string, s string) (*Plugin, error)

func (*Plugin) ImplementationKind

func (p *Plugin) ImplementationKind() string

func (*Plugin) Key

func (p *Plugin) Key(f string) string

func (*Plugin) Name

func (p *Plugin) Name() string

func (*Plugin) Of

func (p *Plugin) Of(kind string) *Plugin

func (*Plugin) Path

func (p *Plugin) Path() (string, error)

func (*Plugin) Unique

func (p *Plugin) Unique() string

func (*Plugin) Validate

func (p *Plugin) Validate()

type Project

type Project struct {
	Name         string       `yaml:"name"`
	Style        ProjectStyle `yaml:"style"`
	Domain       string       `yaml:"domain"`
	Organization string       `yaml:"organization"`
	RelativePath string       `yaml:"relative-path"`

	// Applications in the project
	Applications       []ApplicationEntry `yaml:"applications"`
	CurrentApplication string             `yaml:"current-application"`
}

func CurrentProject

func CurrentProject() (*Project, error)

func ListProjects

func ListProjects() ([]*Project, error)

func LoadCurrentProject

func LoadCurrentProject() (*Project, error)

func LoadProjectFromDir

func LoadProjectFromDir(dir string) (*Project, error)

func LoadProjectFromName

func LoadProjectFromName(name string) (*Project, error)

func MustCurrentProject

func MustCurrentProject() *Project

func (*Project) Dir

func (p *Project) Dir() string

func (*Project) GetService

func (p *Project) GetService(name string) (*Service, error)

func (*Project) ListServices

func (p *Project) ListServices() ([]*ServiceReference, error)

func (*Project) Relative

func (p *Project) Relative(absolute string) string

func (*Project) Save

func (p *Project) Save() error

func (*Project) SaveToDir

func (p *Project) SaveToDir(dir string) error

func (*Project) Unique

func (p *Project) Unique() string

type ProjectBuilder

type ProjectBuilder interface {
	ProjectName() string
	RelativePath() string
	Fetch() error
	Style() ProjectStyle
}

type ProjectInput

type ProjectInput struct {
	Name string
}

func (*ProjectInput) Fetch

func (p *ProjectInput) Fetch() error

func (*ProjectInput) ProjectDir

func (p *ProjectInput) ProjectDir() string

func (*ProjectInput) ProjectName

func (p *ProjectInput) ProjectName() string

func (*ProjectInput) RelativePath

func (p *ProjectInput) RelativePath() string

func (*ProjectInput) Style

func (p *ProjectInput) Style() ProjectStyle

type ProjectReference

type ProjectReference struct {
	Name         string `yaml:"name"`
	RelativePath string `yaml:"relative-path"`
}

func FindProjectReference

func FindProjectReference(name string) (*ProjectReference, error)

type ProjectStyle

type ProjectStyle string
const (
	ProjectStyleUnknown   ProjectStyle = "unknown"
	ProjectStyleMonorepo  ProjectStyle = "monorepo"
	ProjectStyleMultirepo ProjectStyle = "multirepo"
)

func NewStyle

func NewStyle(style string) ProjectStyle

type RunningOptions

type RunningOptions struct {
	Replicas    int  `yaml:"replicas,omitempty"`
	Quiet       bool `yaml:"quiet,omitempty"`
	Persistence bool `yaml:"persistence,omitempty"`
}

RunningOptions of the ServiceReference can tweak running behavior of service Note: this is not a part of the Service configuration but part of the Application running

type Scope

type Scope struct {
	Project     *Project
	Application *Application
}

func WithScope

func WithScope(opts ...Option) *Scope

func (*Scope) WithApplication

func (s *Scope) WithApplication(app *Application) *Scope

type Service

type Service struct {
	Kind         string               `yaml:"kind"`
	Name         string               `yaml:"name"`
	Version      string               `yaml:"version"`
	Application  string               `yaml:"applications"`
	RelativePath string               `yaml:"relative-path"`
	Namespace    string               `yaml:"namespace"`
	Domain       string               `yaml:"domain"`
	Plugin       *Plugin              `yaml:"plugin"`
	Dependencies []*ServiceDependency `yaml:"dependencies"`
	Endpoints    []*EndpointEntry     `yaml:"endpoints"`
	Spec         map[string]any       `yaml:"spec"`
}

A Service

Convention: RelativePath from Application

func FindServiceFromName

func FindServiceFromName(name string) (*Service, error)

func LoadService

func LoadService(input string) (*Service, error)

func LoadServiceFromDir

func LoadServiceFromDir(dir string, opts ...Option) (*Service, error)

func LoadServiceFromReference

func LoadServiceFromReference(ref *ServiceReference, opts ...Option) (*Service, error)

func LoadServicesFromInput

func LoadServicesFromInput(inputs ...string) ([]*Service, error)

LoadServicesFromInput from string inputs

func NewService

func NewService(name string, namespace string, plugin *Plugin) (*Service, error)

func (*Service) AddDependencyReference

func (s *Service) AddDependencyReference(requirement *Service) error

AddDependencyReference adds a dependency to the service

func (*Service) AddSpec

func (s *Service) AddSpec(spec any) error

func (*Service) Dir

func (s *Service) Dir() string

func (*Service) Duplicate

func (s *Service) Duplicate(name string) *Service

func (*Service) Endpoint

func (s *Service) Endpoint() string

func (*Service) Reference

func (s *Service) Reference() (*ServiceReference, error)

func (*Service) Save

func (s *Service) Save() error

func (*Service) SaveAtDir

func (s *Service) SaveAtDir(destination string) error

func (*Service) Unique

func (s *Service) Unique() string

type ServiceDependency

type ServiceDependency struct {
	Name                string `yaml:"name"`
	RelativePath        string `yaml:"relative-path"`
	ApplicationOverride string `yaml:"applications,omitempty"`

	Uses []*EndpointEntry `yaml:"uses,omitempty"`
}

func (*ServiceDependency) AsReference

func (s *ServiceDependency) AsReference() *ServiceReference

func (*ServiceDependency) Validate

func (s *ServiceDependency) Validate() error

type ServiceIdentity

type ServiceIdentity struct {
	Name      string
	Namespace string
	Domain    string
}

func Identity

func Identity(conf *Service) *ServiceIdentity

type ServiceReference

type ServiceReference struct {
	Name                string `yaml:"name"`
	RelativePath        string `yaml:"relative-path"`
	ApplicationOverride string `yaml:"applications,omitempty"`

	RunningOptions RunningOptions `yaml:"options,omitempty"`
}

ServiceReference is a reference to a service used by Application configuration

func (*ServiceReference) CreateReplicas

func (ref *ServiceReference) CreateReplicas() []string

func (*ServiceReference) Dir

func (ref *ServiceReference) Dir(opts ...Option) (string, error)

func (*ServiceReference) Validate

func (ref *ServiceReference) Validate() error

type Workspace

type Workspace struct {
	Organization string `yaml:"organization"`
	Domain       string `yaml:"domain"`

	// Projects in the global configuration
	Projects       []*ProjectReference `yaml:"projects"`
	CurrentProject string              `yaml:"current-project,omitempty"`

	// Internal
	FullDir string `yaml:"-"`
}

Workspace configuration for codefly CLI

func Current

func Current() (*Workspace, error)

Current returns the current global configuration

func MustCurrent

func MustCurrent() *Workspace

MustCurrent returns the current global configuration

func (*Workspace) Dir

func (g *Workspace) Dir() string

Dir returns the absolute path to the global configuration directory

func (*Workspace) Relative

func (g *Workspace) Relative(dir string) string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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