Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5a48092

Browse files
committed
Touchups
Signed-off-by: Danny Kopping <danny@coder.com>
1 parent53bbbef commit5a48092

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

‎coderd/runtimeconfig/config.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,19 @@ import (
1111

1212
varErrKeyNotSet=xerrors.New("key is not set")
1313

14-
// TODO: comment
14+
// Value wraps the type used by the serpent library for its option values.
15+
// This gives us a seam should serpent ever move away from its current implementation.
1516
typeValue pflag.Value
1617

18+
// Entry is designed to wrap any type which satisfies the Value interface, which currently all serpent.Option instances do.
19+
// serpent.Option provide configurability to Value instances, and we use this Entry type to extend the functionality of
20+
// those Value instances.
1721
typeEntry[TValue]struct {
1822
kstring
1923
vT
2024
}
2125

26+
// New creates a new T instance with a defined key and value.
2227
funcNew[TValue](key,valstring) (outEntry[T],errerror) {
2328
out.k=key
2429

@@ -29,6 +34,7 @@ func New[T Value](key, val string) (out Entry[T], err error) {
2934
returnout,nil
3035
}
3136

37+
// MustNew is like New but panics if an error occurs.
3238
funcMustNew[TValue](key,valstring)Entry[T] {
3339
out,err:=New[T](key,val)
3440
iferr!=nil {
@@ -37,13 +43,15 @@ func MustNew[T Value](key, val string) Entry[T] {
3743
returnout
3844
}
3945

46+
// val fronts the T value in the struct, and initializes it should the value be nil.
4047
func (e*Entry[T])val()T {
4148
ifreflect.ValueOf(e.v).IsNil() {
4249
e.v=create[T]()
4350
}
4451
returne.v
4552
}
4653

54+
// key returns the configured key, or fails with ErrKeyNotSet.
4755
func (e*Entry[T])key() (string,error) {
4856
ife.k=="" {
4957
return"",ErrKeyNotSet
@@ -52,29 +60,36 @@ func (e *Entry[T]) key() (string, error) {
5260
returne.k,nil
5361
}
5462

63+
// SetKey allows the key to be set.
5564
func (e*Entry[T])SetKey(kstring) {
5665
e.k=k
5766
}
5867

68+
// Set is an alias of SetStartupValue.
5969
func (e*Entry[T])Set(sstring)error {
6070
returne.SetStartupValue(s)
6171
}
6272

63-
func (e*Entry[T])SetStartupValue(sstring)error {
64-
returne.val().Set(s)
65-
}
66-
73+
// MustSet is like Set but panics on error.
6774
func (e*Entry[T])MustSet(sstring) {
6875
err:=e.val().Set(s)
6976
iferr!=nil {
7077
panic(err)
7178
}
7279
}
7380

81+
// SetStartupValue sets the value of the wrapped field. This ONLY sets the value locally, not in the store.
82+
// See SetRuntimeValue.
83+
func (e*Entry[T])SetStartupValue(sstring)error {
84+
returne.val().Set(s)
85+
}
86+
87+
// Type returns the wrapped value's type.
7488
func (e*Entry[T])Type()string {
7589
returne.val().Type()
7690
}
7791

92+
// String returns the wrapper value's string representation.
7893
func (e*Entry[T])String()string {
7994
returne.val().String()
8095
}
@@ -86,6 +101,7 @@ func (e *Entry[T]) StartupValue() T {
86101
returne.val()
87102
}
88103

104+
// SetRuntimeValue attempts to update the runtime value of this field in the store via the given Mutator.
89105
func (e*Entry[T])SetRuntimeValue(ctx context.Context,mMutator,valT)error {
90106
key,err:=e.key()
91107
iferr!=nil {
@@ -95,6 +111,7 @@ func (e *Entry[T]) SetRuntimeValue(ctx context.Context, m Mutator, val T) error
95111
returnm.UpsertRuntimeSetting(ctx,key,val.String())
96112
}
97113

114+
// UnsetRuntimeValue removes the runtime value from the store.
98115
func (e*Entry[T])UnsetRuntimeValue(ctx context.Context,mMutator)error {
99116
key,err:=e.key()
100117
iferr!=nil {
@@ -104,6 +121,7 @@ func (e *Entry[T]) UnsetRuntimeValue(ctx context.Context, m Mutator) error {
104121
returnm.DeleteRuntimeSetting(ctx,key)
105122
}
106123

124+
// Resolve attempts to resolve the runtime value of this field from the store via the given Resolver.
107125
func (e*Entry[T])Resolve(ctx context.Context,rResolver) (T,error) {
108126
varzeroT
109127

@@ -124,6 +142,8 @@ func (e *Entry[T]) Resolve(ctx context.Context, r Resolver) (T, error) {
124142
returninst,nil
125143
}
126144

145+
// Coalesce attempts to resolve the runtime value of this field from the store via the given Resolver. Should no runtime
146+
// value be found, the startup value will be used.
127147
func (e*Entry[T])Coalesce(ctx context.Context,rResolver) (T,error) {
128148
varzeroT
129149

‎coderd/runtimeconfig/spec.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,16 @@ package runtimeconfig
22

33
import"context"
44

5-
typeInitializerinterface {
6-
Init(keystring)
7-
}
8-
5+
// Resolver is an interface for resolving runtime settings.
96
typeResolverinterface {
7+
// GetRuntimeSetting gets a runtime setting by key.
108
GetRuntimeSetting(ctx context.Context,keystring) (string,error)
119
}
1210

11+
// Mutator is an interface for mutating runtime settings.
1312
typeMutatorinterface {
13+
// UpsertRuntimeSetting upserts a runtime setting by key.
1414
UpsertRuntimeSetting(ctx context.Context,key,valstring)error
15+
// DeleteRuntimeSetting deletes a runtime setting by key.
1516
DeleteRuntimeSetting(ctx context.Context,keystring)error
1617
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp