Documentation
¶
Overview ¶
Package projectconfig owns the on-disk .sofarpc project configuration format shared by CLI setup and MCP project initialization.
Index ¶
- Constants
- func AppendGitignoreEntry(body, entry string) (string, bool)
- func ConfigPath(projectRoot string, kind Kind) string
- func Existing(path string) (bool, error)
- func HasProfile(cfg Config, name string) bool
- func LockProject(root string) (*os.File, error)
- func Marshal(cfg Config) ([]byte, error)
- func MarshalMerged(cfg Config, allowedServicesSet bool) ([]byte, error)
- func ProfileHasFields(p ProfileConfig) bool
- func Validate(cfg Config) error
- type Config
- type GitignoreResult
- type Kind
- type ProfileConfig
- type ReadResult
- type WriteResult
Constants ¶
const LocalGitignoreEntry = ".sofarpc/config.local.json"
Variables ¶
This section is empty.
Functions ¶
func AppendGitignoreEntry ¶
func ConfigPath ¶
func HasProfile ¶
HasProfile reports whether cfg already defines a profile named name.
func LockProject ¶
LockProject serializes configuration changes made by tool processes under the same OS user.
func MarshalMerged ¶
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.
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 SetDefaultProfile ¶
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 ¶
func EnsureLocalConfigIgnored ¶
func EnsureLocalConfigIgnored(projectRoot string) (GitignoreResult, error)
func LocalConfigIgnoreStatus ¶
func LocalConfigIgnoreStatus(projectRoot string) (GitignoreResult, 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 WriteResult ¶
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.