File tree Expand file tree Collapse file tree 11 files changed +140
-69
lines changed Expand file tree Collapse file tree 11 files changed +140
-69
lines changed Original file line number Diff line number Diff line change
1
+ name : CI
2
+ on : [push, pull_request]
3
+
4
+ jobs :
5
+ build :
6
+ runs-on : ubuntu-latest
7
+ strategy :
8
+ matrix :
9
+ go : ["1.17"]
10
+ name : Go ${{ matrix.go }} sample
11
+ steps :
12
+ - uses : actions/checkout@v3
13
+ - name : Setup go
14
+ uses : actions/setup-go@v2
15
+ with :
16
+ go-version : ${{ matrix.go }}
17
+ - run : |
18
+ go build cmd/main.go
Original file line number Diff line number Diff line change 20
20
language : ["go"]
21
21
steps :
22
22
- name : Checkout repository
23
- uses : actions/checkout@v2
23
+ uses : actions/checkout@v3
24
24
- name : Initialize CodeQL
25
25
uses : github/codeql-action/init@v1
26
26
with :
Original file line number Diff line number Diff line change
1
+ name : goreleaser
2
+
3
+ on :
4
+ push :
5
+ tags :
6
+ - " *"
7
+
8
+ permissions :
9
+ contents : write
10
+
11
+ jobs :
12
+ goreleaser :
13
+ runs-on : ubuntu-latest
14
+ steps :
15
+ - name : Checkout
16
+ uses : actions/checkout@v3
17
+ with :
18
+ fetch-depth : 0
19
+ - name : Set up Go
20
+ uses : actions/setup-go@v2
21
+ with :
22
+ go-version : 1.17
23
+ - name : Run GoReleaser
24
+ uses : goreleaser/goreleaser-action@v2
25
+ with :
26
+ distribution : goreleaser
27
+ version : latest
28
+ args : release --rm-dist
29
+ env :
30
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
Load Diff This file was deleted.
Original file line number Diff line number Diff line change 1
1
package cmd
2
2
3
3
import (
4
- "github.com/UltiRequiem/quotable/pkg"
5
- "github.com/fatih/color"
4
+ "flag"
5
+ "fmt"
6
+ "strconv"
7
+ "sync"
8
+
9
+ chigo "github.com/UltiRequiem/chigo/pkg"
10
+ quotable "github.com/UltiRequiem/quotable/pkg"
6
11
)
7
12
8
- // Print a random quote and his/her Author
9
13
func Execute () {
10
- quote , author := quotable .GetRandomQuoteAndAuthor ()
11
- color .Cyan (" " + quote )
12
- color .Green (" - " + author )
14
+ flag .Parse ()
15
+
16
+ times := flag .Arg (0 )
17
+
18
+ if times == "" {
19
+ times = "1"
20
+ }
21
+
22
+ parsedTimes , errorParsingNumber := strconv .Atoi (times )
23
+
24
+ if errorParsingNumber != nil {
25
+ fmt .Println ("The input was not a valid number." )
26
+ panic (errorParsingNumber )
27
+ }
28
+
29
+ var wg sync.WaitGroup
30
+
31
+ wg .Add (parsedTimes )
32
+
33
+ for i := 0 ; i < parsedTimes ; i ++ {
34
+ go func () {
35
+ data , error := quotable .GetQuotable ()
36
+
37
+ if error != nil {
38
+ panic (error )
39
+ }
40
+
41
+ message := fmt .Sprintf ("%s\n -%s" , data .Content , data .Author )
42
+
43
+ fmt .Println (chigo .Colorize (message ))
44
+
45
+ wg .Done ()
46
+ }()
47
+ }
48
+
49
+ wg .Wait ()
13
50
}
Original file line number Diff line number Diff line change @@ -2,4 +2,4 @@ module github.com/UltiRequiem/quotable
2
2
3
3
go 1.16
4
4
5
- require github.com/fatih/color v1.12 .0
5
+ require github.com/UltiRequiem/chigo v1.4 .0
Original file line number Diff line number Diff line change 1
- github.com/fatih/color v1.12.0 h1:mRhaKNwANqRgUBGKmnI5ZxEk7QXmjQeCcuYFMX2bfcc =
2
- github.com/fatih/color v1.12.0 /go.mod h1:ELkj/draVOlAH/xkhN6mQ50Qd0MPOk5AAr3maGEBuJM =
3
- github.com/mattn/go-colorable v0.1.8 h1:c1ghPdyEDarC70ftn0y+A/Ee++9zz8ljHG1b13eJ0s8 =
4
- github.com/mattn/go-colorable v0.1.8 /go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc =
5
- github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY =
6
- github.com/mattn/go-isatty v0.0.12 /go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU =
7
- golang.org/x/sys v0.0.0-20200116001909-b77594299b42 /go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs =
8
- golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae h1:/WDfKMnPU+m5M4xB+6x4kaepxRw6jWvR5iDRdvjHgy8 =
9
- golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae /go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs =
1
+ github.com/UltiRequiem/chigo v1.4.0 h1:3QDR9FiHZPXfk0A7gqtdwEBfkDTH7LpIdQcqF60Rt3Y =
2
+ github.com/UltiRequiem/chigo v1.4.0 /go.mod h1:Bsp2C4AalTn4jfgv4XXCb5OGO/+TFxdbV3SwO7mgLH0 =
3
+ github.com/mattn/go-colorable v0.1.12 /go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4 =
4
+ github.com/mattn/go-isatty v0.0.14 /go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94 =
5
+ golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c /go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg =
6
+ golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6 /go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg =
Original file line number Diff line number Diff line change 1
- # MIT License
1
+ MIT License
2
2
3
- Copyright (c) 2021 Eliaz Bobadilla
3
+ Copyright (c) 2022 Eliaz Bobadilla
4
4
5
5
Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
of this software and associated documentation files (the "Software"), to deal
Original file line number Diff line number Diff line change 1
- // Package quotable exports Quotable Struct and FetchQuotabler Method
2
1
package quotable
3
2
4
- import "encoding/json"
3
+ import (
4
+ "encoding/json"
5
+ "io/ioutil"
6
+ "net/http"
7
+ )
5
8
6
- // Quotable API Response Schema
7
9
type Quotable struct {
8
10
Id string `json:"_id"`
9
11
Tags []string `json:"tags"`
@@ -15,18 +17,26 @@ type Quotable struct {
15
17
DateModified string `json:"dateModified"`
16
18
}
17
19
18
- // Fetches the Quotable API.
19
- func GetQuotableObject () Quotable {
20
- var data string = parseHttpResponse (fetch ("https://api.quotable.io/random" ))
20
+ const (
21
+ quotableApiUrl = "https://api.quotable.io/random"
22
+ )
23
+
24
+ func GetQuotable () (Quotable , error ) {
25
+ response , getError := http .Get (quotableApiUrl )
26
+
27
+ if getError != nil {
28
+ return Quotable {}, getError
29
+ }
30
+
31
+ responseData , readError := ioutil .ReadAll (response .Body )
32
+
33
+ if readError != nil {
34
+ return Quotable {}, readError
35
+ }
21
36
22
37
var parsedData Quotable
23
- json .Unmarshal ([]byte (data ), & parsedData )
24
38
25
- return parsedData
26
- }
39
+ json .Unmarshal (responseData , & parsedData )
27
40
28
- // Return a random quote and author.
29
- func GetRandomQuoteAndAuthor () (string , string ) {
30
- quotableFetch := GetQuotableObject ()
31
- return quotableFetch .Content , quotableFetch .Author
41
+ return parsedData , nil
32
42
}
Load Diff This file was deleted.
You can’t perform that action at this time.
0 commit comments