Skip to content

Commit f96d49f

Browse files
committed
remove val.Def()
1 parent 1d3b20c commit f96d49f

File tree

3 files changed

+12
-17
lines changed

3 files changed

+12
-17
lines changed

modules/setting/config/value.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ type Value[T any] struct {
2828

2929
func (value *Value[T]) parse(key, valStr string) (v T) {
3030
v = value.def
31-
if valStr != "" {
31+
if valStr != "" && valStr != "null" {
3232
if err := json.Unmarshal(util.UnsafeStringToBytes(valStr), &v); err != nil {
3333
log.Error("Unable to unmarshal json config for key %q, err: %v", key, err)
3434
}
@@ -79,10 +79,6 @@ func (value *Value[T]) DynKey() string {
7979
return value.dynKey
8080
}
8181

82-
func (value *Value[T]) Def() T {
83-
return value.def
84-
}
85-
8682
func (value *Value[T]) WithDefault(def T) *Value[T] {
8783
value.def = def
8884
return value

routers/web/admin/config.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -207,19 +207,18 @@ func ChangeConfig(ctx *context.Context) {
207207
return "false", nil
208208
}
209209

210-
marshalStringWithDefault := func(def string) func(v string) (string, error) {
211-
return func(v string) (string, error) {
212-
if strings.TrimSpace(v) == "" {
213-
v = def
214-
}
215-
b, err := json.Marshal(v)
216-
if err != nil {
217-
return "", err
218-
}
219-
return string(b), nil
210+
marshalString := func(v string) (string, error) {
211+
if strings.TrimSpace(v) == "" {
212+
return "null", nil
220213
}
214+
b, err := json.Marshal(v)
215+
if err != nil {
216+
return "", err
217+
}
218+
return string(b), nil
221219
}
222220

221+
223222
marshalOpenWithApps := func(value string) (string, error) {
224223
lines := strings.Split(value, "\n")
225224
var openWithEditorApps setting.OpenWithEditorAppsType
@@ -248,7 +247,7 @@ func ChangeConfig(ctx *context.Context) {
248247
cfg.Picture.DisableGravatar.DynKey(): marshalBool,
249248
cfg.Picture.EnableFederatedAvatar.DynKey(): marshalBool,
250249
cfg.Repository.OpenWithEditorApps.DynKey(): marshalOpenWithApps,
251-
cfg.Template.GitRemoteName.DynKey(): marshalStringWithDefault(cfg.Template.GitRemoteName.Def()),
250+
cfg.Template.GitRemoteName.DynKey(): marshalString,
252251
}
253252
marshaller, hasMarshaller := marshallers[key]
254253
if !hasMarshaller {

templates/admin/config_settings.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
<form class="ui form form-fetch-action" method="post" action="{{AppSubUrl}}/-/admin/config?key={{.SystemConfig.Template.GitRemoteName.DynKey}}">
4848
<div class="field" data-field-patched="true">
4949
<label for="remote_name">{{ctx.Locale.Tr "admin.config.empty_repo_page.git_remote_name"}}</label>
50-
<input id="remote_name" name="value" value="{{.SystemConfig.Template.GitRemoteName.Value ctx}}" maxlength="100" dir="auto" placeholder="{{.SystemConfig.Template.GitRemoteName.Def}}">
50+
<input id="remote_name" name="value" value="{{.SystemConfig.Template.GitRemoteName.Value ctx}}" maxlength="100" dir="auto" required>
5151
</div>
5252
<div class="field">
5353
<button class="ui primary button">{{ctx.Locale.Tr "save"}}</button>

0 commit comments

Comments
 (0)