projectconfig

package
v0.0.0-...-c671013 Latest Latest
Warning

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

Go to latest
Published: Dec 2, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package projectconfig owns the on-disk .sofarpc project configuration format shared by CLI setup and MCP project initialization.

Index

Constants

View Source
const LocalGitignoreEntry = ".sofarpc/config.local.json"

Variables

This section is empty.

Functions

func AppendGitignoreEntry

func AppendGitignoreEntry(body, entry string) (string, bool)

func ConfigPath

func ConfigPath(projectRoot string, kind Kind) string

func Existing

func Existing(path string) (bool, error)

func HasProfile

func HasProfile(cfg Config, name string) bool

HasProfile reports whether cfg already defines a profile named name.

func LockProject

func LockProject(root string) (*os.File, error)

LockProject serializes configuration changes made by tool processes under the same OS user.

func Marshal

func Marshal(cfg Config) ([]byte, error)

func MarshalMerged

func MarshalMerged(cfg Config, allowedServicesSet bool) ([]byte, error)

MarshalMerged is Marshal but, when allowedServicesSet is true, preserves an explicitly-empty legacy allowedServices value during a read-modify-write. Older clients distinguish an empty list from an absent field.

func ProfileHasFields

func ProfileHasFields(p ProfileConfig) bool

ProfileHasFields reports whether p carries at least one target/wire field or invocation property — an empty profile is a no-op and callers should reject it.

func Validate

func Validate(cfg Config) error

Types

type Config

type Config struct {
	DirectURL        string `json:"directUrl,omitempty"`
	Protocol         string `json:"protocol,omitempty"`
	Serialization    string `json:"serialization,omitempty"`
	UniqueID         string `json:"uniqueId,omitempty"`
	TimeoutMS        int    `json:"timeoutMs,omitempty"`
	ConnectTimeoutMS int    `json:"connectTimeoutMs,omitempty"`
	// AllowedServices is legacy config retained for compatibility with older clients.
	AllowedServices      []string                     `json:"allowedServices,omitempty"`
	InvocationProperties invocationprops.Declarations `json:"invocationProperties,omitempty"`
	// DefaultProfile names the Target Profile to use when a call selects
	// none. A local declaration wins over a shared one (see ADR 0003).
	DefaultProfile string `json:"defaultProfile,omitempty"`
	// Profiles holds named Target Profiles. The top-level fields above act
	// as Base Target Settings that a selected profile overlays.
	Profiles map[string]ProfileConfig `json:"profiles,omitempty"`
}

func Normalize

func Normalize(cfg Config) Config

func SetDefaultProfile

func SetDefaultProfile(cfg Config, name string) Config

SetDefaultProfile returns a copy of cfg with DefaultProfile set to name.

func SetProfile

func SetProfile(cfg Config, name string, profile ProfileConfig) Config

SetProfile returns a copy of cfg with profiles[name] set to profile, leaving every other field (including other profiles) untouched. It is a pure transform; callers own read/write and force semantics.

type GitignoreResult

type GitignoreResult struct {
	Path    string
	Entry   string
	Changed bool
}

func EnsureLocalConfigIgnored

func EnsureLocalConfigIgnored(projectRoot string) (GitignoreResult, error)

func LocalConfigIgnoreStatus

func LocalConfigIgnoreStatus(projectRoot string) (GitignoreResult, error)

type Kind

type Kind string
const (
	KindLocal  Kind = "local"
	KindShared Kind = "shared"
)

func ParseKind

func ParseKind(raw string) (Kind, error)

type ProfileConfig

type ProfileConfig struct {
	DirectURL            string                       `json:"directUrl,omitempty"`
	Protocol             string                       `json:"protocol,omitempty"`
	Serialization        string                       `json:"serialization,omitempty"`
	UniqueID             string                       `json:"uniqueId,omitempty"`
	TimeoutMS            int                          `json:"timeoutMs,omitempty"`
	ConnectTimeoutMS     int                          `json:"connectTimeoutMs,omitempty"`
	InvocationProperties invocationprops.Declarations `json:"invocationProperties,omitempty"`
}

ProfileConfig is one named Target Profile inside a project config file. It holds target, wire, and invocation-context fields. The strict parser accepts legacy allowedServices only at the top level.

type ReadResult

type ReadResult struct {
	Path               string
	Kind               Kind
	Exists             bool
	Config             Config
	AllowedServicesSet bool
}

func Read

func Read(projectRoot string, kind Kind) (ReadResult, error)

type WriteResult

type WriteResult struct {
	Path      string
	Body      []byte
	Overwrote bool
}

func Write

func Write(projectRoot string, kind Kind, cfg Config, force bool) (WriteResult, error)

func WriteMerged

func WriteMerged(projectRoot string, kind Kind, cfg Config, allowedServicesSet bool) (WriteResult, error)

WriteMerged writes cfg to the kind's path unconditionally — it is the caller's responsibility to have merged non-destructively (read-modify-write). Unlike Write there is no force gate, because a merge intentionally rewrites the whole file from already-merged content. allowedServicesSet preserves an explicitly-empty allowlist (see MarshalMerged). Overwrote reports whether a file was already present.

Jump to

Keyboard shortcuts

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