project

package
Version: v0.3.1 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2021 License: Apache-2.0 Imports: 8 Imported by: 49

Documentation

Index

Constants

View Source
const DefaultProjectFileName = "nirvana.yaml"

DefaultProjectFileName is the default project file name of a nirvana project.

Variables

This section is empty.

Functions

func FindDefaultProjectFile

func FindDefaultProjectFile(directory string) (string, error)

FindDefaultProjectFile finds the path of nirvana.yaml. It will find the path itself and its parents recursively.

func FindProjectFile

func FindProjectFile(directory string, fileName string) (string, error)

FindProjectFile finds the path of project file. It will find the path itself and its parents recursively.

func GoPath

func GoPath(directory string) (goPath string, absPath string, err error)

GoPath finds the go path and absolute path for specified directory.

func PackageForPath

func PackageForPath(directory string) (string, error)

PackageForPath gets package path for a path.

func Subdirectories

func Subdirectories(vendor bool, paths ...string) []string

Subdirectories walkthroughs all subdirectories. The results contains itself. The path will be ignored if: 1. The path is non-existent 2. Go module is disabled and the path is not in GOPATH 3. Go modules is enabled and the path doesn't belong to a go module

Types

type Config

type Config struct {
	// Root is the directory of this config.
	Root string `yaml:"-"`
	// Project is project name.
	Project string `yaml:"project"`
	// Description describes this project.
	Description string `yaml:"description"`
	// Schemes contains all schemes of APIs.
	// Values must be in "http", "https", "ws", "wss".
	Schemes []string `yaml:"schemes"`
	// Hosts contains the host address to access APIs.
	// It's values can be "domain:port" or "ip:port".
	Hosts []string `yaml:"hosts"`
	// BasePath is the URL prefix for all API paths.
	BasePath string `yaml:"basePath"`
	// Contacts contains maintainers of this project.
	Contacts []Contact `yaml:"contacts"`
	// Versions describes API versions.
	Versions []Version `yaml:"versions"`
}

Config describes configurations of a project.

func LoadConfig

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

LoadConfig loads config from yaml file.

func LoadDefaultProjectFile

func LoadDefaultProjectFile(directory string) (*Config, error)

LoadDefaultProjectFile finds the path of nirvana.yaml and loads it. It will find the directory itself and its parents recursively.

func (*Config) Validate

func (c *Config) Validate() error

Validate validates this config.

type Contact

type Contact struct {
	// Name is maintainer's name.
	Name string `yaml:"name"`
	// Email is maintainer's email.
	Email string `yaml:"email"`
	// Description describes the dutis of this maintainer.
	Description string `yaml:"description"`
}

Contact describes a project maintainer.

type PathRule

type PathRule struct {
	// Prefix indicates a prefix of path.
	Prefix string `yaml:"prefix"`
	// Regexp is a regular expression. Prefix and Regexp are mutually exclusive.
	// If a prefix is specified, this field will be ignored.
	Regexp string `yaml:"regexp"`

	// Replacement is used to replace path parts matched by Prefix or Regexp.
	// In a concrete case, such as we need to export our apis with a gateway. The gateway
	// redirects "/component-name/v1" to "/api/v1". Then we should generate api docs and
	// clients with prefix "/component-name/v1". Then set Prefix to "/api/v1" and
	// Replacement to "/component-name/v1".
	Replacement string `yaml:"replacement"`
	// contains filtered or unexported fields
}

PathRule describes a path rule.

func (*PathRule) Check

func (r *PathRule) Check(path string) bool

Check checks if a path is matched by this rule.

func (*PathRule) Replace

func (r *PathRule) Replace(path string) string

Replace replaces a path with replacement. If path is not matched, returns empty string.

func (*PathRule) Validate

func (r *PathRule) Validate() error

Validate validates this rule.

type Version

type Version struct {
	// Module is the name of the module to which the version belongs.
	// optional, can be empty if there is only one module
	Module string `yaml:"module"`
	// Name is version number. SemVer is recommended.
	Name string `yaml:"name"`
	// Description describes this version.
	Description string `yaml:"description"`
	// Schemes overrides the same field in config.
	Schemes []string `yaml:"schemes"`
	// Hosts overrides the same field in config.
	Hosts []string `yaml:"hosts"`
	// BasePath is the URL prefix for all API paths.
	BasePath string `yaml:"basePath"`
	// Contacts overrides the same field in config.
	Contacts []Contact `yaml:"contacts"`
	// PathRules contains a list of regexp rules to match path.
	PathRules []PathRule `yaml:"rules"`
}

Version describes an API version.

func (*Version) Validate

func (v *Version) Validate() error

Validate validates this version.

Source Files

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL