Skip to content

Commit 7217cfd

Browse files
committed
♻️ Updates
closes #1 and #2
1 parent 5690594 commit 7217cfd

File tree

11 files changed

+140
-69
lines changed

11 files changed

+140
-69
lines changed

.github/workflows/ci.yaml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
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

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ jobs:
2020
language: ["go"]
2121
steps:
2222
- name: Checkout repository
23-
uses: actions/checkout@v2
23+
uses: actions/checkout@v3
2424
- name: Initialize CodeQL
2525
uses: github/codeql-action/init@v1
2626
with:

.github/workflows/goreleaser.yaml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
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 }}

.travis.yml

Lines changed: 0 additions & 4 deletions
This file was deleted.

cmd/root.go

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,50 @@
11
package cmd
22

33
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"
611
)
712

8-
// Print a random quote and his/her Author
913
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()
1350
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ module github.com/UltiRequiem/quotable
22

33
go 1.16
44

5-
require github.com/fatih/color v1.12.0
5+
require github.com/UltiRequiem/chigo v1.4.0

go.sum

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
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=

LICENSE.md renamed to license

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# MIT License
1+
MIT License
22

3-
Copyright (c) 2021 Eliaz Bobadilla
3+
Copyright (c) 2022 Eliaz Bobadilla
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

pkg/root.go

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1-
// Package quotable exports Quotable Struct and FetchQuotabler Method
21
package quotable
32

4-
import "encoding/json"
3+
import (
4+
"encoding/json"
5+
"io/ioutil"
6+
"net/http"
7+
)
58

6-
// Quotable API Response Schema
79
type Quotable struct {
810
Id string `json:"_id"`
911
Tags []string `json:"tags"`
@@ -15,18 +17,26 @@ type Quotable struct {
1517
DateModified string `json:"dateModified"`
1618
}
1719

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+
}
2136

2237
var parsedData Quotable
23-
json.Unmarshal([]byte(data), &parsedData)
2438

25-
return parsedData
26-
}
39+
json.Unmarshal(responseData, &parsedData)
2740

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
3242
}

pkg/utils.go

Lines changed: 0 additions & 27 deletions
This file was deleted.

0 commit comments

Comments
 (0)