config

package
v2.0.0-beta.1 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package config finds and reads the repo-local flagsmith.json.

Index

Constants

View Source
const FileName = "flagsmith.json"

FileName is the project config file discovered in the working tree.

Variables

View Source
var ErrServerSideKey = errors.New("`environment` holds a server-side key, which is a secret")

ErrServerSideKey means the file's `environment` field holds a server-side (ser.) key, which is a secret and must not be committed.

Functions

func Discover

func Discover(dir string) (string, error)

Discover returns the path of the nearest flagsmith.json, walking up from dir to the git toplevel. Outside a git repository only dir itself is checked — a stray file higher up the tree never applies silently. Returns "" when no file is found.

Types

type File

type File struct {
	Schema       string `json:"$schema,omitempty"`
	Project      *Ref   `json:"project,omitempty"`
	Organisation *Ref   `json:"organisation,omitempty"`
	Environment  string `json:"environment,omitempty"`
	APIURL       string `json:"apiUrl,omitempty"`
	SDKAPIURL    string `json:"sdkApiUrl,omitempty"`

	// Extra holds unrecognised fields verbatim so they survive a Load/Save
	// round trip instead of being silently dropped — a newer file edited by an
	// older CLI, say. Not covered by the struct tags: MarshalJSON re-emits it
	// after the known fields.
	Extra map[string]json.RawMessage `json:"-"`
}

File is the parsed flagsmith.json. Zero values mean "not set".

func Load

func Load(path string) (*File, []string, error)

Load reads and validates a flagsmith.json. Unknown fields produce warnings, not errors, for forward compatibility; a server-side key in `environment` is an error — those are secrets and never belong in a committed file.

func (File) MarshalJSON

func (f File) MarshalJSON() ([]byte, error)

MarshalJSON emits the known fields in their declared order, then appends any Extra fields so a Load/Save round trip preserves them.

func (*File) Save

func (f *File) Save(path string) error

Save writes f to path as indented JSON, atomically: it writes a temp file in the same directory and renames it into place, so an interrupted write never leaves a truncated or partial flagsmith.json.

type Ref

type Ref struct {
	ID   int
	Name string
}

Ref is a project or organisation reference: either a numeric ID or a name. An all-digit reference (given as a JSON number or a numeric string) is an ID; anything else is a name resolved via the Admin API. The nil *Ref means "not set".

func (Ref) MarshalJSON

func (r Ref) MarshalJSON() ([]byte, error)

func (*Ref) UnmarshalJSON

func (r *Ref) UnmarshalJSON(b []byte) error

func (*Ref) Value

func (r *Ref) Value() any

Value returns the reference as an int ID, a string name, or nil when unset.

Jump to

Keyboard shortcuts

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