Skip to content

Commit

Permalink
Added function for creating schedule.Client
Browse files Browse the repository at this point in the history
  • Loading branch information
y0rune committed Oct 29, 2022
1 parent 69d9023 commit 3af07be
Showing 1 changed file with 19 additions and 10 deletions.
29 changes: 19 additions & 10 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,24 @@ var defaultSchedule = [...]og.Restriction{
StartMin: &startMinuteWorkWeek,
},
}

func createApi(apiKey string) *schedule.Client {
if apiKey == "" {
fmt.Printf("Empty apiKey... Please use -apiKey \n")
os.Exit(1)
}

scheduleClient, err := schedule.NewClient(&client.Config{
ApiKey: apiKey,
})

if err != nil {
fmt.Printf("Error in scheduleClient create: %d", err)
}

return scheduleClient
}

func getFirstMonday(year int, month time.Month) int {
t := time.Date(year, month, 1, 0, 0, 0, 0, time.UTC)
firstMonday := ((8-int(t.Weekday()))%7 + 1)
Expand Down Expand Up @@ -149,17 +167,8 @@ func main() {
delete := flag.Bool("delete", false, "# Delete schedule ")
flag.Parse()

if (*apiKey == "") || (apiKey == nil) {
fmt.Printf("Empty apiKey... Please use -apiKey \n")
os.Exit(1)
}
scheduleClient := createApi(*apiKey)

scheduleClient, err := schedule.NewClient(&client.Config{
ApiKey: *apiKey,
})

if err != nil {
fmt.Printf("Error in scheduleClient create: %d", err)
if *delete && *scheduleName == "TestSchedule" && *scheduleID != "XXXXXXXXXXXXXXX" {
deleteSchedule(*scheduleClient, *scheduleID)
}
Expand Down

0 comments on commit 3af07be

Please sign in to comment.