-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ENC-921] Add Config API's to public contract (#11)
This commit adds the new `encore.dev/config` API's to the `encore.dev` module. It also adds new comments explaining to users why we panic in this code, and provides a link to go to the current implementation of the given function.
- Loading branch information
Showing
26 changed files
with
1,067 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// Package config provides a simple way to access configuration values for a | ||
// service using the Load function. | ||
// | ||
// # By default configuration is pulled at build time from CUE files in each service directory | ||
// | ||
// For more information about configuration see https://encore.dev/docs/develop/config. | ||
package config | ||
|
||
// Load returns the fully loaded configuration for this service. | ||
// | ||
// The configuration is loaded from the CUE files in the service directory and | ||
// will be validated by Encore at compile time, which ensures this function will | ||
// return a valid configuration at runtime. | ||
// | ||
// Encore will generate a `encore.gen.cue` file in the service directory which | ||
// will contain generated CUE matching the configuration type T. | ||
// | ||
// Note: This function can only be called from within services and cannot be | ||
// referenced from other services. | ||
func Load[T any]() T { | ||
// Encore will provide an implementation to this function at runtime, we do not expose | ||
// the implementation in the API contract as it is an implementation detail, which may change | ||
// between releases. | ||
// | ||
// The current implementation of this function can be found here: | ||
// https://github.com/encoredev/encore/blob/v1.9.0/runtime/config/pkgfn.go#L25-L41 | ||
panic("encore apps must be run using the encore command") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package config | ||
|
||
import ( | ||
"time" | ||
|
||
"encore.dev/types/uuid" | ||
) | ||
|
||
// Value represents a value in the configuration for this application | ||
// which can be any value represented in the configuration files. | ||
// | ||
// It is a function because the underlying value could change while | ||
// the application is still running due to unit tests providing | ||
// overrides to test different behaviours. To change the value within | ||
// a single unit test, use the et.SetCfg function. | ||
type Value[T any] func() T | ||
|
||
// Values represents a list of values in the configuration for this | ||
// application which can be any value represented in the configuration files. | ||
// | ||
// It is a function because the underlying value could change while | ||
// the application is still running due to unit tests providing | ||
// overrides to test different behaviours. | ||
type Values[T any] func() []T | ||
|
||
type Bool = Value[bool] | ||
type Int8 = Value[int8] | ||
type Int16 = Value[int16] | ||
type Int32 = Value[int32] | ||
type Int64 = Value[int64] | ||
type Uint8 = Value[uint8] | ||
type Uint16 = Value[uint16] | ||
type Uint32 = Value[uint32] | ||
type Uint64 = Value[uint64] | ||
type Float32 = Value[float32] | ||
type Float64 = Value[float64] | ||
type String = Value[string] | ||
type Bytes = Value[[]byte] | ||
type Time = Value[time.Time] | ||
type UUID = Value[uuid.UUID] | ||
type Int = Value[int] | ||
type Uint = Value[uint] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package et | ||
|
||
import ( | ||
"encore.dev/config" | ||
) | ||
|
||
// SetCfg changes the value of cfg to newValue within the current test and any subtests. | ||
// Other tests running will not be affected. | ||
// | ||
// It does not support setting slices and panics if given a config value that is a slice. | ||
func SetCfg[T any](cfg config.Value[T], newValue T) { | ||
// Encore will provide an implementation to this function at runtime, we do not expose | ||
// the implementation in the API contract as it is an implementation detail, which may change | ||
// between releases. | ||
// | ||
// The current implementation of this function can be found here: | ||
// https://github.com/encoredev/encore/blob/v1.9.0/runtime/et/config.go#L13-L23 | ||
panic("encore apps must be run using the encore command") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.