project

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: May 14, 2025 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package project defines a tiny project structure

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateConfig

func CreateConfig(service, endpoint, method, module, file string) error

Types

type BoolValue

type BoolValue struct {
	Value bool
}

func (*BoolValue) GetValue

func (b *BoolValue) GetValue() interface{}

type Config added in v0.2.0

type Config struct {
	Name     string
	FieldMap map[string]*Field
	Options  Options
}

func NewConfig added in v0.2.0

func NewConfig(name string) *Config

func (*Config) GetAllFields added in v0.2.0

func (m *Config) GetAllFields() []*Field

func (*Config) GetField added in v0.2.0

func (m *Config) GetField(name string) (*Field, bool)

func (*Config) GetFieldNames added in v0.2.0

func (m *Config) GetFieldNames() []string

func (*Config) GetFieldTypes added in v0.2.0

func (m *Config) GetFieldTypes() []string

func (*Config) StructTag added in v0.2.0

func (m *Config) StructTag() string

type Endpoint

type Endpoint struct {
	Name      string
	MethodMap map[string]*Method
}

func (*Endpoint) ClientStructName

func (e *Endpoint) ClientStructName() string

func (*Endpoint) GetAllMethods

func (e *Endpoint) GetAllMethods() []*Method

func (*Endpoint) GetMethod

func (e *Endpoint) GetMethod(name string) (*Method, bool)

type Enum

type Enum struct {
	Name   string
	Values []*KeyValue
}

func (*Enum) GetKeys

func (e *Enum) GetKeys() []string

type Field

type Field struct {
	Optional bool
	Repeated bool
	Required bool
	Name     string
	TypeName string
}

func (*Field) DeclarationName

func (f *Field) DeclarationName() string

func (*Field) DeclarationTag

func (f *Field) DeclarationTag(strct string) string

func (*Field) DeclarationType

func (f *Field) DeclarationType() string

type IntValue

type IntValue struct {
	Value int64
}

func (*IntValue) GetValue

func (i *IntValue) GetValue() interface{}

type KeyValue

type KeyValue struct {
	Key   string
	Value int
}

type Message

type Message struct {
	Name     string
	FieldMap map[string]*Field
	Options  Options
}

func NewMessage

func NewMessage(name string) *Message

func (*Message) GetAllFields

func (m *Message) GetAllFields() []*Field

func (*Message) GetField

func (m *Message) GetField(name string) (*Field, bool)

func (*Message) GetFieldNames

func (m *Message) GetFieldNames() []string

func (*Message) GetFieldTypes

func (m *Message) GetFieldTypes() []string

type Method

type Method struct {
	Name              string
	RequestTypeName   string
	RequestStreaming  bool
	ResponseTypeName  string
	ResponseStreaming bool
}

type NumberValue

type NumberValue struct {
	Value float64
}

func (*NumberValue) GetValue

func (n *NumberValue) GetValue() interface{}

type Option

type Option struct {
	Name  string
	Attr  *string
	Value Valuer
}

func NewOption

func NewOption(name string, attr *string, value *mucl.Value) *Option

type Options

type Options map[string]*Option

Options is a map of option names to their values.

func (Options) Get

func (o Options) Get(name string) (*Option, bool)

Get returns the value of the option with the given name.

func (Options) GetAll

func (o Options) GetAll() []*Option

GetAll returns all options.

func (Options) GetNames

func (o Options) GetNames() []string

GetNames returns the names of all options.

type Project

type Project struct {
	Module  string
	Service *Service
	// contains filtered or unexported fields
}

Project represents a project with a mucl definition file in a dedicated directory.

func NewProject

func NewProject(opts ...ProjectOption) (*Project, error)

NewProject creates a new Project instance with the given options. It initializes the project with default values and applies the provided options. It returns a pointer to the Project instance and an error if any occurs. The default mucl file is "service.mu" and the default output directory is ".". The project is not loaded at this point, so you need to call Init() separately.

func (*Project) Apply

func (p *Project) Apply() error

Apply applies the generator to the project.

func (*Project) GenerateGitIgnore

func (p *Project) GenerateGitIgnore() error

func (*Project) GenerateGoMod

func (p *Project) GenerateGoMod() error

func (*Project) GenerateHandlers

func (p *Project) GenerateHandlers() error

func (*Project) GenerateServers

func (p *Project) GenerateServers() error

func (*Project) GenerateTaskfile

func (p *Project) GenerateTaskfile() error

func (*Project) GenerateTypes

func (p *Project) GenerateTypes() error

func (*Project) Init

func (p *Project) Init() error

func (*Project) Tidy

func (p *Project) Tidy() error

type ProjectOption

type ProjectOption func(*Project)

ProjectOption is a function that configures a Project. It is used to set various options for the project.

func WithForce

func WithForce(force bool) ProjectOption

WithForce sets whether to forcefully overwrite existing files.

func WithMuclFile

func WithMuclFile(muclFile string) ProjectOption

WithMuclFile sets the mucl file for the project.

func WithOnlyTypes

func WithOnlyTypes(onlyTypes bool) ProjectOption

WithOnlyTypes sets whether to only generate types.

func WithOutputDir

func WithOutputDir(outDir string) ProjectOption

WithOutputDir sets the output directory for the project. This is where the generated code will be placed.

type Service

type Service struct {
	Name        string
	Description string
	EndpointMap map[string]*Endpoint
	MessageMap  map[string]*Message
	EnumMap     map[string]*Enum
	ConfigMap   map[string]*Config
}

func (*Service) DirectoryName

func (s *Service) DirectoryName() string

func (*Service) GetAllConfigs added in v0.2.0

func (s *Service) GetAllConfigs() []*Config

func (*Service) GetAllEndpoints

func (s *Service) GetAllEndpoints() []*Endpoint

func (*Service) GetAllEnums

func (s *Service) GetAllEnums() []*Enum

func (*Service) GetAllMessages

func (s *Service) GetAllMessages() []*Message

func (*Service) GetConfig added in v0.2.0

func (s *Service) GetConfig(name string) (*Config, bool)

func (*Service) GetEndpoint

func (s *Service) GetEndpoint(name string) (*Endpoint, bool)

func (*Service) GetEnum

func (s *Service) GetEnum(name string) (*Enum, bool)

func (*Service) GetMessage

func (s *Service) GetMessage(name string) (*Message, bool)

type StringValue

type StringValue struct {
	Value string
}

func (*StringValue) GetValue

func (s *StringValue) GetValue() interface{}

type Valuer

type Valuer interface {
	// GetValue returns the value of the option.
	GetValue() interface{}
}

Directories

Path Synopsis
Package templates provides templates for generating code
Package templates provides templates for generating code

Jump to

Keyboard shortcuts

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