File tree Expand file tree Collapse file tree 2 files changed +18
-8
lines changed
go/callback/internal/config Expand file tree Collapse file tree 2 files changed +18
-8
lines changed Original file line number Diff line number Diff line change 3535
3636 - name : Create test files
3737 run : |
38- echo "Port =8080" > backup.conf
38+ echo "port =8080" > backup.conf
3939 echo "callback_secret=my-test-secret" >> backup.conf
40- echo "ScriptPath =./test-script.sh" >> backup.conf
40+ echo "scriptpath =./test-script.sh" >> backup.conf
4141 echo "#!/bin/bash" > test-script.sh
4242 echo 'echo "script output"' >> test-script.sh
4343 chmod +x test-script.sh
Original file line number Diff line number Diff line change @@ -36,12 +36,22 @@ func LoadConfig(path string) (*Config, error) {
3636 continue
3737 }
3838
39- // 查找 callback_secret
40- if strings .HasPrefix (trimmedLine , "callback_secret" ) {
41- parts := strings .SplitN (trimmedLine , "=" , 2 )
42- if len (parts ) == 2 {
43- config .CallbackSecret = strings .TrimSpace (parts [1 ])
44- }
39+ // 解析键值对
40+ parts := strings .SplitN (trimmedLine , "=" , 2 )
41+ if len (parts ) != 2 {
42+ continue
43+ }
44+ key := strings .TrimSpace (parts [0 ])
45+ value := strings .TrimSpace (parts [1 ])
46+
47+ // 根据键更新配置
48+ switch key {
49+ case "port" :
50+ config .Port = value
51+ case "scriptpath" :
52+ config .ScriptPath = value
53+ case "callback_secret" :
54+ config .CallbackSecret = value
4555 }
4656 }
4757
You can’t perform that action at this time.
0 commit comments