File tree Expand file tree Collapse file tree 3 files changed +7
-27
lines changed
Expand file tree Collapse file tree 3 files changed +7
-27
lines changed Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ const (
2020
2121type BackupProviderConfig struct {
2222 Type BackupProviderConfigType `json:"type"`
23- Config any `json:"config"`
23+ Config json. RawMessage `json:"config"`
2424}
2525
2626type DefaultConfig struct {
@@ -95,15 +95,11 @@ type SyncConfig struct {
9595 Cron string `json:"cron"`
9696}
9797
98- func ConvertToBackupProviderConfig [T any ](raw any ) (* T , error ) {
99- b , err := json .Marshal (raw )
98+ func Convert [T any ](raw json.RawMessage ) (* T , error ) {
99+ conf := new (T )
100+ err := json .Unmarshal (raw , & conf )
100101 if err != nil {
101102 return nil , err
102103 }
103- var conf T
104- err = json .Unmarshal (b , & conf )
105- if err != nil {
106- return nil , err
107- }
108- return & conf , nil
104+ return conf , nil
109105}
Original file line number Diff line number Diff line change @@ -3,7 +3,6 @@ package config
33import (
44 "encoding/json"
55 "fmt"
6- "github.com/TBXark/github-backup/provider/file"
76 "github.com/TBXark/github-backup/provider/gitea"
87 "testing"
98)
@@ -37,22 +36,7 @@ func TestSyncConfig(t *testing.T) {
3736 "[a-zA-Z0-9._-]+/[a-zA-Z0-9._-]+/0/[01]/[01]" : "PUBLIC_GITHUB_TOKEN" ,
3837 },
3938 },
40- Targets : []GithubConfig {
41- {
42- Owner : "GITHUB_OWNER" ,
43- Token : "GITHUB_TOKEN" ,
44- RepoOwner : "BACKUP_TARGET_REPO_OWNER" ,
45- Backup : & BackupProviderConfig {
46- Type : "file" ,
47- Config : & file.FileBackupConfig {
48- Dir : "SAVE_DIR" ,
49- History : "FILE_HISTORY_JSON_PATH" ,
50- },
51- },
52- Filter : & FilterConfig {
53- UnmatchedRepoAction : UnmatchedRepoActionIgnore ,
54- },
55- },
39+ Targets : []* GithubConfig {
5640 {
5741 Owner : "GITHUB_ORG" ,
5842 RepoOwner : "BACKUP_TARGET_REPO_ORG" ,
Original file line number Diff line number Diff line change @@ -13,7 +13,7 @@ import (
1313func BuildBackupProvider (conf * config.BackupProviderConfig ) (provider.Provider , error ) {
1414 switch conf .Type {
1515 case config .BackupProviderConfigTypeGitea :
16- c , err := config.ConvertToBackupProviderConfig [gitea.Config ](conf .Config )
16+ c , err := config.Convert [gitea.Config ](conf .Config )
1717 if err != nil {
1818 return nil , err
1919 }
You can’t perform that action at this time.
0 commit comments