Skip to content

Commit

Permalink
fix(fmt): Apply gofmt to all code
Browse files Browse the repository at this point in the history
  • Loading branch information
Xoan Mallon Moure committed Dec 21, 2020
1 parent bbe9c65 commit 52de526
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 31 deletions.
4 changes: 2 additions & 2 deletions cmd/doc.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ GLOBAL OPTIONS:
--file-numbers-to-check value, -f value JSON file with numbers to check
--notify, -n Activate notifications through PushOver (default: false)
--help, -h show help (default: false)
*/
package main
*/
package main
7 changes: 4 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
// lotteryDrawResultsAPIURL represents the URL of the API where the results of the
// Christmas draw will be obtained
const lotteryDrawResultsAPIURL = "http://api.elpais.com/ws/LoteriaNavidadPremiados"

var date = time.Now().Format(time.RFC3339)

func main() {
Expand All @@ -26,10 +27,10 @@ func buildCLI() *cli.App {
d, _ := time.Parse(time.RFC3339, date)

return &cli.App{
Name: "check-christmas-lottery-numbers",
Usage: "Interacts with the Christmas lottery API to obtain the results " +
Name: "check-christmas-lottery-numbers",
Usage: "Interacts with the Christmas lottery API to obtain the results " +
"of the numbers provided and send notifications with PushOver if you win a prize",
Compiled: d,
Compiled: d,
UsageText: "check-lottery-results --file-numbers-to-check <file-numbers-to-check> [-n]",
Authors: []*cli.Author{
{
Expand Down
3 changes: 1 addition & 2 deletions pkg/notifications/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,9 @@ import (

const pushOverURL = "https://api.pushover.net/1/messages.json"


// GetNecessaryNotificationParams checks if all the necessary
// params are set in the system for make calls to pushOver
func getNecessaryNotificationParams() (*string, *string, error){
func getNecessaryNotificationParams() (*string, *string, error) {
pushOverNotificationToken := os.Getenv("PUSH_OVER_NOTIFICATION_TOKEN")
pushOverNotificationUser := os.Getenv("PUSH_OVER_NOTIFICATION_USER")

Expand Down
6 changes: 3 additions & 3 deletions pkg/notifications/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package notifications
// Notification struct which contain information
// about notification for PushOver app
type Notification struct {
Token string `json:"token"`
User string `json:"user"`
Token string `json:"token"`
User string `json:"user"`
Message string `json:"message"`
}

// NotificationResult struct which contain information
// about notification result for PushOver app
type NotificationResult struct {
Status int `json:"status"`
Status int `json:"status"`
Request string `json:"request"`
}
4 changes: 2 additions & 2 deletions pkg/requests/requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func DoGetRequest(url string) (*string, error) {
}

// DoPostRequestWithBody makes a POST Request with body to a specific URL
func DoPostRequestWithBody (URL string, body []byte) ([]byte, error) {
func DoPostRequestWithBody(URL string, body []byte) ([]byte, error) {
req, err := http.NewRequest("POST", URL, bytes.NewBuffer(body))
if err != nil {
return nil, err
Expand All @@ -43,4 +43,4 @@ func DoPostRequestWithBody (URL string, body []byte) ([]byte, error) {
return nil, err
}
return respBody, nil
}
}
10 changes: 7 additions & 3 deletions pkg/results/results.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ import (
// codeDrawNotStartedYet represents the code returned by the Christmas lottery
// API when the draw has not started
const codeDrawNotStartedYet = 0

// codeDrawStartedWithoutAllNumbers represents the code returned by the Christmas lottery
// API when the draw has started but all the numbers have not been published yet
const codeDrawStartedWithoutAllNumbers = 1

// codeDrawEndWithProvisionalNumbers represents the code returned by the Christmas lottery
// API when the draw has started but the list of numbers is provisional
const codeDrawEndWithProvisionalNumbers = 2

// codeDrawEndWithSemiofficialNumbers represents the code returned by the Christmas lottery
// API when the draw has started but the list of numbers is semi-official
const codeDrawEndWithSemiofficialNumbers = 3

// codeDrawEndWithOfficialNumbers represents the code returned by the Christmas lottery
// API when the draw has started but the list of numbers is official
const codeDrawEndWithOfficialNumbers = 4
Expand Down Expand Up @@ -108,7 +112,7 @@ func CheckNumber(lotteryDrawResultsAPIURL string, number int, bet int, origin st
}

// isNecessaryNotify check if is necessary notify for each number result
func isNecessaryNotify(finalPrize int, notify bool) bool{
func isNecessaryNotify(finalPrize int, notify bool) bool {
if finalPrize > 0 && notify {
return true
}
Expand All @@ -132,7 +136,7 @@ func CheckPersonsNumbers(lotteryDrawResultsAPIURL string, personsNumbersToCheck

personsNumbersToCheckNum := len(personsNumbersToCheck.PersonsNumbers)
log.Printf("Numbers are going to be check from %d different owners\n", personsNumbersToCheckNum)
for i:= 0; i < personsNumbersToCheckNum; i++ {
for i := 0; i < personsNumbersToCheckNum; i++ {
personNumbersToCheck := personsNumbersToCheck.PersonsNumbers[i]
personNumbersToCheckNum := len(personNumbersToCheck.Numbers)

Expand Down Expand Up @@ -171,4 +175,4 @@ func checkPersonNumbers(lotteryDrawResultsAPIURL string, personNumbersToCheck Pe
}
}
return nil
}
}
16 changes: 8 additions & 8 deletions pkg/results/results_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func TestGetAPILotteryDrawStatusIncorrectUrlForJSONUnmarshall(t *testing.T) {
func TestGetAPILotteryDrawStatusIncorrectUrlForRequest(t *testing.T) {
inCorrectLotteryDrawResultsAPIURLForRequest := "http:/api.elpais.com/ws/LoteriaNavidadPremiadoss"
_, err := GetAPILotteryDrawStatus(inCorrectLotteryDrawResultsAPIURLForRequest)
inCorrectLotteryDrawResultsAPIURLForRequestInRequest := "http:///api.elpais.com/ws/LoteriaNavidadPremiadoss"
inCorrectLotteryDrawResultsAPIURLForRequestInRequest := "http:///api.elpais.com/ws/LoteriaNavidadPremiadoss"
expectedError := fmt.Errorf(
"Get \"%s?s=1\": http: no Host in request URL",
inCorrectLotteryDrawResultsAPIURLForRequestInRequest,
Expand All @@ -57,7 +57,7 @@ func TestGetAPILotteryDrawStatusIncorrectUrlForRequest(t *testing.T) {
}

func TestCheckAPILOtteryDrawStatusDrawNotStarted(t *testing.T) {
_ , err := CheckAPILOtteryDrawStatus(0)
_, err := CheckAPILOtteryDrawStatus(0)

expectedError := errors.New("the draw has not started yet, it is not possible to get the results for the numbers")
if err.Error() != expectedError.Error() {
Expand All @@ -66,7 +66,7 @@ func TestCheckAPILOtteryDrawStatusDrawNotStarted(t *testing.T) {
}

func TestCheckAPILOtteryDrawStatusDrawStartedWithoutAllNumbers(t *testing.T) {
message , _ := CheckAPILOtteryDrawStatus(1)
message, _ := CheckAPILOtteryDrawStatus(1)

expectedMessage := "The draw has started but not all the numbers are in the list"

Expand All @@ -76,7 +76,7 @@ func TestCheckAPILOtteryDrawStatusDrawStartedWithoutAllNumbers(t *testing.T) {
}

func TestCheckAPILOtteryDrawStatusDrawFinishedWithProvisionalNumbers(t *testing.T) {
message , _ := CheckAPILOtteryDrawStatus(2)
message, _ := CheckAPILOtteryDrawStatus(2)

expectedMessage := "The draw has ended but the list of numbers is provisional"

Expand All @@ -86,7 +86,7 @@ func TestCheckAPILOtteryDrawStatusDrawFinishedWithProvisionalNumbers(t *testing.
}

func TestCheckAPILOtteryDrawStatusDrawFinishedWithSemiofficialNumbers(t *testing.T) {
message , _ := CheckAPILOtteryDrawStatus(3)
message, _ := CheckAPILOtteryDrawStatus(3)

expectedMessage := "The draw is over but the list of numbers is semi-official"

Expand All @@ -96,7 +96,7 @@ func TestCheckAPILOtteryDrawStatusDrawFinishedWithSemiofficialNumbers(t *testing
}

func TestCheckAPILOtteryDrawStatusDrawFinishedWithOfficialNumbers(t *testing.T) {
message , _ := CheckAPILOtteryDrawStatus(4)
message, _ := CheckAPILOtteryDrawStatus(4)

expectedMessage := "The draw is over and the list of numbers is official"

Expand All @@ -106,7 +106,7 @@ func TestCheckAPILOtteryDrawStatusDrawFinishedWithOfficialNumbers(t *testing.T)
}

func TestCheckAPILOtteryDrawStatusDrawFinishedWithUnknownCode(t *testing.T) {
_ , err := CheckAPILOtteryDrawStatus(5)
_, err := CheckAPILOtteryDrawStatus(5)

expectedError := errors.New("code obtained for draw status is unknown")
if err.Error() != expectedError.Error() {
Expand Down Expand Up @@ -164,4 +164,4 @@ func TestCheckNumbersWithoutNotify(t *testing.T) {
if err != nil {
log.Fatal(err)
}
}
}
9 changes: 4 additions & 5 deletions pkg/results/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@ type Number struct {
// PersonNumbers struct which contains information
// about the numbers to check for a specific Person
type PersonNumbers struct {
Numbers []Number `json:"numbers"`
Owner string `json:"owner"`
Numbers []Number `json:"numbers"`
Owner string `json:"owner"`
}

// PersonNumbersToCheck struct which contains information
// about the numbers to check for a specific Person
type PersonNumbersToCheck struct {
PersonsNumbers []PersonNumbers `json:"numbers_to_check"`
PersonsNumbers []PersonNumbers `json:"numbers_to_check"`
}


// Result struct which contain information about
// each lottery number result obtained from API
type Result struct {
Expand All @@ -34,7 +33,7 @@ type Result struct {

// NewResult allows to create a Result type struct providing all the information for it
func NewResult(numero int, premio int, timestamp int, status int, error int) *Result {
return &Result{numero, premio, timestamp, status, error}
return &Result{numero, premio, timestamp, status, error}
}

// LotteryDrawStatus which contain information about
Expand Down
4 changes: 2 additions & 2 deletions pkg/results/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

// OpenFilePersonsNumbersToCheck open the file where the numbers to check for the persons are stored
func OpenFilePersonsNumbersToCheck(fileNumbersToCheck string) (*PersonNumbersToCheck, error){
func OpenFilePersonsNumbersToCheck(fileNumbersToCheck string) (*PersonNumbersToCheck, error) {
log.Printf("Opening file %s with numbers to check\n", fileNumbersToCheck)
jsonFile, err := os.Open(fileNumbersToCheck)

Expand All @@ -26,4 +26,4 @@ func OpenFilePersonsNumbersToCheck(fileNumbersToCheck string) (*PersonNumbersToC
return nil, err
}
return numbers, nil
}
}
2 changes: 1 addition & 1 deletion pkg/results/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ func TestOpenFileNumbersToCheckFile(t *testing.T) {
if err != nil {
log.Fatal(err)
}
}
}

0 comments on commit 52de526

Please sign in to comment.