Documentation ¶
Index ¶
- type DependencyError
- type IOError
- type PackageAlreadyExistsError
- type PackageConfig
- type PackageInfoLocal
- type PackageInfoRemote
- type PackageNotFoundError
- type PackageState
- func (s *PackageState) AddLocalPackage(pkg PackageInfoLocal) error
- func (s *PackageState) AddPackage(pkg PackageInfoRemote, dependencies ...PackageInfoRemote) error
- func (s PackageState) Download() error
- func (s PackageState) Get(p PackageInfoRemote) (*PackageInfoRemote, bool, error)
- func (s PackageState) GetLocal(p PackageInfoLocal) (*PackageInfoLocal, error)
- func (s PackageState) GetPackageDependencies(info *PackageInfoRemote) ([]PackageInfoRemote, error)
- func (s PackageState) GetTransitive(p PackageInfoRemote) (*PackageInfoRemote, bool, error)
- func (s PackageState) LoadState(state *PackageState) error
- func (s PackageState) MarshalJSON() ([]byte, error)
- func (s *PackageState) RemoveLocalPackage(name string) error
- func (s *PackageState) RemovePackage(name string) error
- func (s PackageState) Save(path string) error
- type ValidationError
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DependencyError ¶
func NewDependencyError ¶
func NewDependencyError(packageName, dependencyName string) *DependencyError
func (DependencyError) Error ¶
func (e DependencyError) Error() string
type PackageAlreadyExistsError ¶
type PackageAlreadyExistsError struct {
Name string
}
func (PackageAlreadyExistsError) Error ¶
func (e PackageAlreadyExistsError) Error() string
type PackageConfig ¶
type PackageConfig struct { CompilerVersion *string `json:"compiler,omitempty"` Dependencies []PackageInfoRemote `json:"dependencies"` LocalDependencies []PackageInfoLocal `json:"localDependencies,omitempty"` TransitiveDependencies []PackageInfoRemote `json:"transitiveDependencies,omitempty"` }
func NewPackageConfig ¶
func NewPackageConfig(raw []byte) (*PackageConfig, error)
type PackageInfoLocal ¶
func (PackageInfoLocal) GetName ¶
func (p PackageInfoLocal) GetName() string
func (PackageInfoLocal) RelativePath ¶
func (p PackageInfoLocal) RelativePath() string
type PackageInfoRemote ¶
type PackageInfoRemote struct { Name string `json:"name"` AlternativeNames []string `json:"alts,omitempty"` Repository string `json:"repository"` Version string `json:"version"` Dependencies []string `json:"dependencies,omitempty"` }
func (*PackageInfoRemote) AddName ¶
func (p *PackageInfoRemote) AddName(name string)
func (PackageInfoRemote) Download ¶
func (p PackageInfoRemote) Download() error
func (PackageInfoRemote) GetName ¶
func (p PackageInfoRemote) GetName() string
func (PackageInfoRemote) RelativePath ¶
func (p PackageInfoRemote) RelativePath() string
type PackageNotFoundError ¶
type PackageNotFoundError struct {
Name string
}
func NewPackageAlreadyExistsError ¶
func NewPackageAlreadyExistsError(name string) *PackageNotFoundError
func NewPackageNotFoundError ¶
func NewPackageNotFoundError(name string) *PackageNotFoundError
func (PackageNotFoundError) Error ¶
func (e PackageNotFoundError) Error() string
type PackageState ¶
type PackageState struct { CompilerVersion *string Dependencies map[string]*PackageInfoRemote LocalDependencies map[string]*PackageInfoLocal TransitiveDependencies map[string]*PackageInfoRemote }
PackageState is the in-memory state of the packages.
Example ¶
package main import ( "fmt" "github.com/internet-computer/oko/config" ) func main() { json, _ := config.EmptyState().MarshalJSON() fmt.Println(string(json)) }
Output: { "dependencies": [] }
func LoadPackageState ¶
func LoadPackageState(path string) (*PackageState, error)
LoadPackageState loads a package config file.
func NewPackageState ¶
func NewPackageState(pkg *PackageConfig) *PackageState
NewPackageState creates a new package state based on the given package config.
func (*PackageState) AddLocalPackage ¶
func (s *PackageState) AddLocalPackage(pkg PackageInfoLocal) error
AddLocalPackage adds the given package to the local package state.
func (*PackageState) AddPackage ¶
func (s *PackageState) AddPackage(pkg PackageInfoRemote, dependencies ...PackageInfoRemote) error
AddPackage adds the given package and its dependencies to the remote package state.
Example ¶
package main import ( "fmt" "github.com/internet-computer/oko/config" ) func main() { state := config.EmptyState() _ = state.AddPackage(config.PackageInfoRemote{ Name: "test", Repository: "url", Version: "*", }) json, _ := state.MarshalJSON() fmt.Println(string(json)) }
Output: { "dependencies": [ { "name": "test", "repository": "url", "version": "*" } ] }
Example (AlreadyExits) ¶
package main import ( "fmt" "github.com/internet-computer/oko/config" ) func main() { state := config.EmptyState() dep := config.PackageInfoRemote{ Name: "test", Repository: "url", Version: "*", } _ = state.AddPackage(dep) _ = state.AddPackage(config.PackageInfoRemote{ Dependencies: []string{"test"}, }, dep) json, _ := state.MarshalJSON() fmt.Println(string(json)) }
Output: { "dependencies": [ { "name": "", "repository": "", "version": "", "dependencies": [ "test" ] }, { "name": "test", "repository": "url", "version": "*" } ] }
Example (FromTransitive) ¶
package main import ( "fmt" "github.com/internet-computer/oko/config" ) func main() { state := config.EmptyState() dep := config.PackageInfoRemote{ Name: "test", Repository: "url", Version: "*", } _ = state.AddPackage(config.PackageInfoRemote{ Name: "test-v0.1.0", Repository: "url", Version: "v0.1.0", Dependencies: []string{"test"}, }, dep) json, _ := state.MarshalJSON() fmt.Println(string(json)) _ = state.AddPackage(dep) json, _ = state.MarshalJSON() fmt.Println(string(json)) }
Output: { "dependencies": [ { "name": "test-v0.1.0", "repository": "url", "version": "v0.1.0", "dependencies": [ "test" ] } ], "transitiveDependencies": [ { "name": "test", "repository": "url", "version": "*" } ] } { "dependencies": [ { "name": "test", "repository": "url", "version": "*" }, { "name": "test-v0.1.0", "repository": "url", "version": "v0.1.0", "dependencies": [ "test" ] } ] }
func (PackageState) Download ¶
func (s PackageState) Download() error
Download downloads all dependencies (including transitive dependencies).
func (PackageState) Get ¶
func (s PackageState) Get(p PackageInfoRemote) (*PackageInfoRemote, bool, error)
Get returns the package matching the given package info. `true` get returns if the package also has the same name.
func (PackageState) GetLocal ¶
func (s PackageState) GetLocal(p PackageInfoLocal) (*PackageInfoLocal, error)
Get returns the package matching the given package info. Returns an error if a package with the same name already exists.
func (PackageState) GetPackageDependencies ¶
func (s PackageState) GetPackageDependencies(info *PackageInfoRemote) ([]PackageInfoRemote, error)
GetPackageDependencies returns a list of (copied) package dependencies.
func (PackageState) GetTransitive ¶
func (s PackageState) GetTransitive(p PackageInfoRemote) (*PackageInfoRemote, bool, error)
Get returns the package matching the given package info. `true` get returns if the package also has the same name.
func (PackageState) LoadState ¶
func (s PackageState) LoadState(state *PackageState) error
LoadState loads in another package state.
Example ¶
package main import ( "fmt" "github.com/internet-computer/oko/config" ) func main() { state := config.EmptyState() _ = state.AddPackage(config.PackageInfoRemote{ Name: "test", Repository: "url", Version: "*", }) other := config.EmptyState() _ = state.LoadState(&other) json, _ := state.MarshalJSON() fmt.Println(string(json)) }
Output: { "dependencies": [ { "name": "test", "repository": "url", "version": "*" } ] }
func (PackageState) MarshalJSON ¶
func (s PackageState) MarshalJSON() ([]byte, error)
MarshalJSON converts the state to raw (formatted) JSON.
func (*PackageState) RemoveLocalPackage ¶
func (s *PackageState) RemoveLocalPackage(name string) error
RemoveLocalPackage removes the local package with the given name.
func (*PackageState) RemovePackage ¶
func (s *PackageState) RemovePackage(name string) error
RemovePackage removes the package with the given name
Example ¶
package main import ( "fmt" "github.com/internet-computer/oko/config" ) func main() { state := config.EmptyState() _ = state.AddPackage(config.PackageInfoRemote{ Name: "test", Repository: "url", Version: "*", }) _ = state.RemovePackage("test") json, _ := state.MarshalJSON() fmt.Println(string(json)) }
Output: { "dependencies": [] }
func (PackageState) Save ¶
func (s PackageState) Save(path string) error
Save writes the state to the given path.
type ValidationError ¶
type ValidationError struct {
Err error
}
func NewValidationError ¶
func NewValidationError(err error) *ValidationError
func (ValidationError) Error ¶
func (e ValidationError) Error() string