Skip to content

Commit d2ccb17

Browse files
committed
feat: 添加ToRaw函数以支持将配置转换为json.RawMessage
1 parent 2f6bb38 commit d2ccb17

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

config/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,11 @@ func Convert[T any](raw json.RawMessage) (*T, error) {
103103
}
104104
return conf, nil
105105
}
106+
107+
func ToRaw[T any](conf T) json.RawMessage {
108+
raw, err := json.Marshal(conf)
109+
if err != nil {
110+
return nil
111+
}
112+
return raw
113+
}

config/config_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ func TestSyncConfig(t *testing.T) {
1414
RepoOwner: "BACKUP_TARGET_REPO_OWNER",
1515
Backup: &BackupProviderConfig{
1616
Type: "gitea",
17-
Config: &gitea.Config{
17+
Config: ToRaw(&gitea.Config{
1818
Host: "GITEA_HOST",
1919
Token: "GITEA_TOKEN",
2020
AuthUsername: "GITEA_USERNAME",
21-
},
21+
}),
2222
},
2323
Filter: &FilterConfig{
2424
UnmatchedRepoAction: UnmatchedRepoActionDelete,

0 commit comments

Comments
 (0)