project

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package project manages the per-project .morth.json configuration file. Each project directory contains a .morth.json that defines which services the project uses and their port assignments.

Index

Constants

View Source
const ConfigFile = ".morth.json"

ConfigFile is the name of the per-project configuration file.

Variables

This section is empty.

Functions

func DefaultPath

func DefaultPath() string

DefaultPath returns the default config file path: .morth.json in the current working directory.

func Exists

func Exists(path string) bool

Exists reports whether a project config file exists at the given path.

Types

type Config

type Config struct {
	ProjectID string                   `json:"project_id"`
	Services  map[string]ServiceConfig `json:"services"`
	// contains filtered or unexported fields
}

Config represents the per-project .morth.json configuration.

func Init

func Init(path string, projectID string) (*Config, error)

Init creates a new project configuration at the given path. The project ID is derived from the directory name containing the config file. Returns an error if a config file already exists at the path.

func Load

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

Load reads a project configuration from the given file path. Returns an error if the file does not exist.

func (*Config) AddService

func (c *Config) AddService(name string, preferredPort int)

AddService adds a service to the configuration with the given preferred port. Use preferredPort of 0 for automatic port assignment.

func (*Config) GetService

func (c *Config) GetService(name string) (ServiceConfig, bool)

GetService returns the service configuration for the named service. The second return value indicates whether the service was found.

func (*Config) RemoveService

func (c *Config) RemoveService(name string)

RemoveService removes a service from the configuration. If the service does not exist, this is a no-op.

func (*Config) Save

func (c *Config) Save() error

Save writes the configuration to disk with 0644 permissions. The JSON is pretty-printed with indentation.

func (*Config) SetAssigned

func (c *Config) SetAssigned(name string, port int)

SetAssigned sets the assigned port for the named service. If the service does not exist in the configuration, this is a no-op.

type ServiceConfig

type ServiceConfig struct {
	Port     int `json:"port,omitempty"`     // preferred port (0 = auto)
	Assigned int `json:"assigned,omitempty"` // actually assigned port
}

ServiceConfig holds the port configuration for a single service.

Jump to

Keyboard shortcuts

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