diff --git a/cmd/api/api.go b/pkg/api/api.go similarity index 91% rename from cmd/api/api.go rename to pkg/api/api.go index d10d551..f5779d4 100644 --- a/cmd/api/api.go +++ b/pkg/api/api.go @@ -7,7 +7,7 @@ import ( "os" ) -func apiRequest(subUrlPath string) (string, error) { +func ApiRequest(subUrlPath string) (string, error) { droneUrl := os.Getenv("DRONE_URL") token := os.Getenv("TOKEN") diff --git a/cmd/drivers/influxdb.go b/pkg/drivers/influxdb.go similarity index 100% rename from cmd/drivers/influxdb.go rename to pkg/drivers/influxdb.go diff --git a/main.go b/pkg/repository/repository.go similarity index 83% rename from main.go rename to pkg/repository/repository.go index d42a65c..1e6f235 100644 --- a/main.go +++ b/pkg/repository/repository.go @@ -1,16 +1,15 @@ -package main +package repository import ( "encoding/json" "fmt" - "github.com/jlehtimaki/drone-exporter/cmd/api" - //"github.com/jlehtimaki/drone_exporter@initial/cmd/drivers/influxdb" + "github.com/jlehtimaki/drone-exporter/pkg/api" ) type Repo struct { Id int `json:"Id"` Name string `json:"Name"` - Active bool `json:"Active"` + Active bool `json:"Active"` Namespace string `json:"Namespace"` } @@ -40,9 +39,9 @@ func (rwb *RepoWithBuilds) AddBuild(build Build){ rwb.Builds = append(rwb.Builds, build) } -func getRepos() error { +func GetRepos() error { var subUrlPath = "/api/user/repos" - data, err := api.apiRequest(subUrlPath) + data, err := api.ApiRequest(subUrlPath) if err != nil { return fmt.Errorf("could not get repos: %w", err) } @@ -71,7 +70,7 @@ func getBuilds(repos Repo, rbw RepoWithBuilds) (RepoWithBuilds, error) { subUrlPath := fmt.Sprintf("/api/repos/%s" + "/%s/builds", repos.Namespace, repos.Name) - data, err := api.apiRequest(subUrlPath) + data, err := api.ApiRequest(subUrlPath) if err != nil { return rbw, fmt.Errorf("could not get builds: %w", err) } @@ -87,10 +86,3 @@ func getBuilds(repos Repo, rbw RepoWithBuilds) (RepoWithBuilds, error) { return rbw, nil } - -func main() { - err := getRepos() - if err != nil { - fmt.Printf("error: %s", err) - } -} \ No newline at end of file