This repository has been archived by the owner on Nov 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit d8237e0
Showing
5 changed files
with
142 additions
and
0 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,23 @@ | ||
name: Publish | ||
|
||
on: push | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
with: | ||
fetch-depth: 0 | ||
- name: Set up Go | ||
uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.16 | ||
- name: Run GoReleaser | ||
uses: goreleaser/goreleaser-action@v2 | ||
with: | ||
version: latest | ||
args: release --rm-dist | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
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,2 @@ | ||
dist/ | ||
go.sum |
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,31 @@ | ||
project_name: rocket | ||
before: | ||
hooks: | ||
- go mod tidy | ||
- go generate ./... | ||
builds: | ||
- env: | ||
- CGO_ENABLED=0 | ||
main: ./main.go | ||
binary: rocket | ||
goos: | ||
- linux | ||
- windows | ||
- darwin | ||
archives: | ||
- replacements: | ||
darwin: Darwin | ||
linux: Linux | ||
windows: Windows | ||
386: i386 | ||
amd64: x86_64 | ||
checksum: | ||
name_template: 'checksums.txt' | ||
snapshot: | ||
name_template: "{{ .Tag }}-next" | ||
changelog: | ||
sort: asc | ||
filters: | ||
exclude: | ||
- '^docs:' | ||
- '^test:' |
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,5 @@ | ||
module quentinguidee.io/rocket-launches | ||
|
||
go 1.14 | ||
|
||
require github.com/fatih/color v1.10.0 |
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,81 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"flag" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/fatih/color" | ||
) | ||
|
||
type Launch struct { | ||
Name string | ||
Details string | ||
Rocket string | ||
Date_utc string | ||
} | ||
|
||
type Rocket struct { | ||
Name string | ||
} | ||
|
||
func main() { | ||
flag.String("command", "next", "Command to execute") | ||
flag.Parse() | ||
|
||
launch := new(Launch) | ||
rocket := new(Rocket) | ||
|
||
fmt.Println() | ||
font := color.New(color.FgHiMagenta).Add(color.Bold) | ||
|
||
if flag.Arg(0) == "latest" { | ||
font.Println("=> LATEST LAUNCH\n") | ||
GetLatestLaunch(launch) | ||
} else { | ||
font.Println("=> NEXT LAUNCH\n") | ||
GetNextLaunch(launch) | ||
} | ||
GetRocket(rocket, launch.Rocket) | ||
PrintLaunch(launch, rocket) | ||
} | ||
|
||
func PrintLaunch(launch *Launch, rocket *Rocket) { | ||
PrintLine("Name", launch.Name) | ||
PrintLine("Date", launch.Date_utc) | ||
PrintLine("Rocket", rocket.Name) | ||
PrintLine("Description", launch.Details) | ||
} | ||
|
||
func PrintLine(tag string, content string) { | ||
titleFont := color.New(color.FgYellow).Add(color.Bold) | ||
|
||
titleFont.Printf(tag + " ") | ||
fmt.Println(content) | ||
} | ||
|
||
func GetLatestLaunch(launch interface{}) error { | ||
return Request("launches/latest", launch) | ||
} | ||
|
||
func GetNextLaunch(launch interface{}) error { | ||
return Request("launches/next", launch) | ||
} | ||
|
||
func GetRocket(rocket interface{}, id string) error { | ||
return Request("rockets/"+id, rocket) | ||
} | ||
|
||
func Request(path string, object interface{}) error { | ||
resp, err := http.Get("https://api.spacexdata.com/v4/" + path) | ||
|
||
if err != nil { | ||
log.Fatalln(err) | ||
} | ||
|
||
defer resp.Body.Close() | ||
|
||
return json.NewDecoder(resp.Body).Decode(object) | ||
} |