github.go 810 B

1234567891011121314151617181920212223242526272829303132333435
  1. package service
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/google/go-github/v36/github"
  6. "github.com/tidwall/gjson"
  7. )
  8. type GithubService interface {
  9. GetManifestJsonByRepo() (image, tcp, udp string)
  10. }
  11. type githubService struct {
  12. cl *github.Client
  13. }
  14. func (g *githubService) GetManifestJsonByRepo() (image, tcp, udp string) {
  15. c, _, _, e := g.cl.Repositories.GetContents(context.Background(), "a624669980", "o_test_json", "/OasisManifest.json", &github.RepositoryContentGetOptions{})
  16. if e != nil {
  17. fmt.Println(e)
  18. }
  19. str, e := c.GetContent()
  20. if e != nil {
  21. fmt.Println(e)
  22. }
  23. image = gjson.Get(str, "dockerImage").String()
  24. tcp = gjson.Get(str, "tcp_ports").Raw
  25. udp = gjson.Get(str, "udp_ports").Raw
  26. return
  27. }
  28. func GetNewGithubService(cl *github.Client) GithubService {
  29. return &githubService{cl: cl}
  30. }