-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
64 lines (58 loc) · 1.21 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
// AGPL License
// Copyright (c) 2021 ysicing <i@ysicing.me>
package main
import (
"bufio"
"encoding/json"
"fmt"
"github.com/ysicing/habor-sync/api"
"k8s.io/klog/v2"
"os"
)
var haborapi *api.Client
func init() {
c := api.NewClient("", "", "https://old.hub/api")
haborapi =c
klog.InitFlags(nil)
}
func main() {
ps, _, err := haborapi.Project.List()
if err != nil {
panic(err)
}
piddata := make(map[string]interface{})
for _, p := range *ps {
repos, _, err := haborapi.Repositories.List(p.ProjectID)
if err != nil {
continue
}
// Notice: 忽略某些项目
if p.Name == "test" || len(*repos) == 0 {
continue
}
for _, repo := range *repos {
old := fmt.Sprintf("old.hub/%v", repo.Name)
new := fmt.Sprintf("new.hub/%v", repo.Name)
piddata[old] = new
}
}
data, err := json.Marshal(piddata)
if err != nil {
panic(err)
}
if err := Writefile("image.json", string(data)); err != nil {
panic(err)
}
}
// Writefile 写文件
func Writefile(logpath, msg string) (err error) {
file, err := os.OpenFile(logpath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0777)
if err != nil {
return err
}
defer file.Close()
write := bufio.NewWriter(file)
write.WriteString(msg)
write.Flush()
return nil
}