utils

package
v0.0.0-...-378a893 Latest Latest
Warning

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

Go to latest
Published: Jun 20, 2025 License: MIT Imports: 23 Imported by: 0

Documentation

Overview

---------------------------------------------------------------------------- General utilities for handling collections ----------------------------------------------------------------------------

---------------------------------------------------------------------------- The code here is about the configuration of Aldev ----------------------------------------------------------------------------

---------------------------------------------------------------------------- The code here is about cancelable contexts, to help gracefully stop some processes ----------------------------------------------------------------------------

---------------------------------------------------------------------------- The code here is about local deployment with Containers / Kubernetes / Tilt ----------------------------------------------------------------------------

---------------------------------------------------------------------------- The code here is about local deployment without Containers / Kubernetes / Tilt ----------------------------------------------------------------------------

---------------------------------------------------------------------------- The code here is about downloading external resources ----------------------------------------------------------------------------

---------------------------------------------------------------------------- The code here is about file manipulations ----------------------------------------------------------------------------

---------------------------------------------------------------------------- The code here is about handling HTTP requests ----------------------------------------------------------------------------

---------------------------------------------------------------------------- Downloading translations from a Google sheet into a local, structured file ----------------------------------------------------------------------------

---------------------------------------------------------------------------- The code here is about logging in the shell ----------------------------------------------------------------------------

---------------------------------------------------------------------------- The code here is about running stuff in parallel ----------------------------------------------------------------------------

---------------------------------------------------------------------------- The code here is about executing shell commands ----------------------------------------------------------------------------

---------------------------------------------------------------------------- Creates the required symlinks, if missing ----------------------------------------------------------------------------

---------------------------------------------------------------------------- The code here is about building files from templates, and Aldev config ----------------------------------------------------------------------------

---------------------------------------------------------------------------- The code here is responsible for fetching source code and copy-pasting it into our project, as configured ----------------------------------------------------------------------------

Index

Constants

View Source
const AldevCacheDirENVVAR = "ALDEV_CACHEDIR"
View Source
const (
	TagHOTSWAPPED = "___HOTSWAPPED___"
)

Variables

This section is empty.

Functions

func CreateMissingSymlinks(ctx CancelableContext)

Checks if the required symlinks exist, else creates them

func Debug

func Debug(str string, params ...any)

func DeployToLocalCluster

func DeployToLocalCluster(ctx CancelableContext)

func DeployWithNoContainer

func DeployWithNoContainer(ctx CancelableContext)

func DirExists

func DirExists(dirPaths ...string) (string, bool)

func DownloadExternalResources

func DownloadExternalResources(ctx CancelableContext)

Downloading external resources, like translations, vendors, etc

func EnsureConfigmap

func EnsureConfigmap()

Making sure we have a ConfigMap to pass to K8S before deploying to a local cluster

func EnsureDir

func EnsureDir(ctx CancelableContext, pathElem ...string) string

func EnsureFileFromTemplate

func EnsureFileFromTemplate(filepath, tpl string, params ...any)

func EnsureNoDir

func EnsureNoDir(ctx CancelableContext, pathElem ...string) string

func Error

func Error(str string, params ...any)

func ErrorAndCancel

func ErrorAndCancel(ctx CancelableContext, str string, params ...any)

func Fatal

func Fatal(ctx CancelableContext, str string, params ...any)

func FatalErr

func FatalErr(ctx CancelableContext, err error)

func FatalIfErr

func FatalIfErr(ctx CancelableContext, err error)

func FileExists

func FileExists(dirPaths ...string) (string, bool)

func GenerateDeployConfigs

func GenerateDeployConfigs(ctx CancelableContext, dockerAllowed bool)

func GetBinDir

func GetBinDir() string

func GetConfigPath

func GetConfigPath() string

func GetGoSrcDir

func GetGoSrcDir() string

returns the name of the folder where to find the Go source code

func InSlice

func InSlice[V comparable](s []V, el V) bool

InSlice returns true if the slice s contains the given element el

func Info

func Info(str string, params ...any)

func InitAldevContext

func InitAldevContext(waitTimeMs int, stopFn func()) *aldevContext

func InstallGitHooks

func InstallGitHooks(ctx CancelableContext)

Installing Git hooks to unify our practices

func IsDevAPI

func IsDevAPI() bool

func IsDevLibrary

func IsDevLibrary() bool

func IsDevNative

func IsDevNative() bool

func IsDevWebApp

func IsDevWebApp() bool

func IsLinux

func IsLinux() bool

func IsWindows

func IsWindows() bool

func MapFn

func MapFn[T any, U any](slice []T, fn func(T) U) []U

MapFn applies a function to each element of a slice and returns a new slice.

func NewBaseContext

func NewBaseContext() *baseCancelableContext

func QuickRun

func QuickRun(whyRunThis string, commandAsString string, params ...any)

func ReadConfig

func ReadConfig(cfgFileName string)

func ReadFile

func ReadFile(ctx CancelableContext, filename string, failIfNotExist bool) []byte

func ReadFileToJson

func ReadFileToJson[T any, Y *T](ctx CancelableContext, filename string, obj Y, failIfNotExist bool) Y

func Recover

func Recover(ctx CancelableContext, msg string, params ...any)

func ReplaceInFile

func ReplaceInFile(ctx CancelableContext, filename string, replacements map[string]string)

func Run

func Run(whyRunThis string, ctx CancelableContext, logStart bool, commandAsString string, params ...any)

func RunAndGet

func RunAndGet(whyRunThis string, execDir string, logStart bool, commandAsString string, params ...any) []byte

func RunJobs

func RunJobs(aldevCtx CancelableContext, parallel bool)

func SetVerbose

func SetVerbose(isVerbose bool)

func Step

func Step(str string, params ...any)

func StepWithPreamble

func StepWithPreamble(preamble, str string, params ...any)

func UseCodeSwaps

func UseCodeSwaps()

func Warn

func Warn(str string, params ...any)

func WatcherFor

func WatcherFor(filepaths ...string) *fsnotify.Watcher

func WriteBytesToFile

func WriteBytesToFile(ctx CancelableContext, filename string, bytes []byte)

func WriteJsonObjToFile

func WriteJsonObjToFile(ctx CancelableContext, filename string, obj any)

func WriteStringToFile

func WriteStringToFile(ctx CancelableContext, filename string, content string, params ...any)

Types

type AldevConfig

type AldevConfig struct {
	AppName   string // the name of the app - beware: the key has to be "appname" in the YAML file
	Languages string // the languages available for this app, seperated by a comma - for example: en,fr,it,de,zh,es
	Lib       *struct {
		SrcDir  string // where the library source code can be found
		Config  string // the path to the config file for the API, from the API's folder
		Install string // command that should be run to install stuff, like needed dependencies, etc.
		Develop string // command that should be run to allow for continuously developping & building the library
		BinDir  string // the directory where to find the library's compiled binary, as seen from the library source folder (srcdir)
		// contains filtered or unexported fields
	}
	API *struct {
		SrcDir  string // where the API's Goald-based code should be found
		Config  string // the path to the config file for the API, from the API's folder
		Port    int    // the port used to expose the whole load-balanced API service
		I18n    *I18nConfig
		DataDir string // where to find bootstraping data to run the app
		BinDir  string // the directory where to find the API's compiled binary, as seen from the API source folder (srcdir)
		// contains filtered or unexported fields
	}
	// APIOnly bool      // if true, then no web app is handled
	Web *struct {
		SrcDir  string // where the Web app's GoaldR-based code should be found
		Port    int    // the port used to expose the app's frontend
		EnvVars []*struct {
			Name  string // the variable name; must start with "WEB_"
			Desc  string // a description for the
			Value string // the value we're using for the local dev environment
		}
	}
	Native *struct {
		SrcDir  string      // where the Native app's GoaldN-based code should be found
		I18n    *I18nConfig //
		DataDir string      // where to find bootstraping data to run the app
	}
	Vendors   []*VendorConfig // external projects to vendor into our project
	Deploying *struct {
		Dir string // where all the deploying config should be
	}
	CodeSwaps []*CodeSwapsConfig // Automatically, temporarily swapping bits of code
	Symlinks  []*SymlinkConfig   // Create symlinks, to help code-swapping for instance
	Jobs      []*JobConfig       // Jobs to run
}

func Config

func Config() *AldevConfig

func (*AldevConfig) ResolvedBinDir

func (cfg *AldevConfig) ResolvedBinDir() string

computed property on an Aldev config object

type AldevContext

type AldevContext interface {
	CancelableContext
	GetLoopCtx() CancelableContext
	RestartLoop()
}

an Aldev Context has a loop and allows to restart it

type AldevTask

type AldevTask func(ctx CancelableContext)

characterises the functions run during an aldev command or subcommand

type CancelableContext

type CancelableContext interface {
	context.Context
	WithExecDir(...string) CancelableContext

	WithStdOutWriter(io.Writer) CancelableContext

	WithStdErrWriter(io.Writer) CancelableContext

	WithErrLogFn(errLogFn) CancelableContext

	WithEnvVars(...string) CancelableContext

	WithReRun() CancelableContext

	WithAllowFailure(bool) CancelableContext

	CancelAll()
	NewChildContext() CancelableContext
	// contains filtered or unexported methods
}

type CmdConfig

type CmdConfig struct {
	Exec   string // the command to run
	From   string // the path from which to run the command
	FailOK bool   // if true, then the command is allowed to fail
}

type CodeSwapsConfig

type CodeSwapsConfig struct {
	From string   // the path from which to look for swaps; "." for the current project, "../../dependency" to swap in another lib
	For  []string // the file paths for which to apply the same swaps; can be provided as a glob, e.g. "./src/**/*.ts?",
	Do   []*struct {
		Replace string // the substring to look for and replace
		With    string // the replacement
		EOFCom  bool   // should the added comment (HOTSWAPPED) be at the end of the line (// ...) rather than inline (/* ... */) ?
	}
}

type I18nConfig

type I18nConfig struct {
	Links   []string // the link to download the translations from; each new file can override previous translations
	KeySize int      // the max size of the key in the translation UID namespace.key
	Folder  string   // the path of the file where to write the downloaded translations
}

type JobConfig

type JobConfig struct {
	Description string       // a short description of the job
	Cmds        []*CmdConfig // a list of commands to run
}

type SymlinkConfig

type SymlinkConfig struct {
	Link string // what to link
	As   string // how to link it
}

type VendorConfig

type VendorConfig struct {
	Repo    string // the repo of the external project
	Version string // the maximal version to fetch; can also be the "latest"
	From    string // the path inside the repo to copy; if void, then all the repo is copied
	To      string // the place where to paste the copied cod
}

Jump to

Keyboard shortcuts

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