-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
list: implemented projects & services sub-command
- Loading branch information
Showing
5 changed files
with
105 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"os" | ||
) | ||
|
||
type Project struct { | ||
ProjectBody GenericBody `json:"project"` | ||
} | ||
|
||
type GenericBody struct { | ||
Id int `json:"id"` | ||
Name string `json:"name"` | ||
Note string `json:"note"` | ||
} | ||
|
||
type Service struct { | ||
ServiceBody GenericBody `json:"service"` | ||
} | ||
|
||
func apiGetProjects() (projects []Project) { | ||
client := &http.Client{} | ||
req := buildGetRequest("/projects.json") | ||
res, err := client.Do(req) | ||
if err != nil { | ||
_, _ = fmt.Fprintln(os.Stderr, err) | ||
} | ||
|
||
defer res.Body.Close() | ||
err = json.NewDecoder(res.Body).Decode(&projects) | ||
if err != nil { | ||
_, _ = fmt.Fprintln(os.Stderr, err) | ||
} | ||
return projects | ||
} | ||
|
||
func buildGetRequest(path string) *http.Request { | ||
url := fmt.Sprintf("%s%s", configGetApiUrl(), path) | ||
req, err := http.NewRequest("GET", url, nil) | ||
if err != nil { | ||
_, _ = fmt.Fprintln(os.Stderr, err) | ||
} | ||
req.Header.Add("X-MiteApiKey", configGetApiKey()) | ||
|
||
return req | ||
} | ||
|
||
func apiGetServices() (services []Service) { | ||
client := &http.Client{} | ||
req := buildGetRequest("/services.json") | ||
res, err := client.Do(req) | ||
if err != nil { | ||
_, _ = fmt.Fprintln(os.Stderr, err) | ||
} | ||
|
||
defer res.Body.Close() | ||
err = json.NewDecoder(res.Body).Decode(&services) | ||
if err != nil { | ||
_, _ = fmt.Fprintln(os.Stderr, err) | ||
} | ||
return services | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,10 @@ | ||
module github.com/phiros/mite-go | ||
|
||
require ( | ||
github.com/BurntSushi/toml v0.3.1 // indirect | ||
github.com/cheynewallace/tabby v1.1.0 | ||
github.com/inconshreveable/mousetrap v1.0.0 // indirect | ||
github.com/mitchellh/go-homedir v1.1.0 | ||
github.com/spf13/cobra v0.0.3 | ||
github.com/spf13/viper v1.3.1 | ||
rsc.io/quote v1.5.2 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters