calendarific

package module
v0.0.0-...-e560f36 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 27, 2019 License: MIT Imports: 6 Imported by: 0

README

go-calendarific

Official Go library for Calendarific Global Holiday API

Installation

dep ensure -add https://github.com/calendarific/go-calendarific

Usage / Example

  • Create a file called main.go & insert a script like below
    package main
    
    import (
    	"fmt"
    	"github.com/calendarific/go-calendarific"
    	"os"
    )
    
    func main() {
    
        // Loading the paramater struct
    	cp := calendarific.CalParameters{
    		ApiKey:  "<MY SECRET API KEY>",
    		Country: "US",
    		Year:    2019,
    	}
    
    	// It returns a response struct
    	holidays, err := cp.CalData()
    	if err != nil {
    		fmt.Println(err)
    		os.Exit(1)
    	}
    
    	fmt.Println(holidays)
    }
    

Check out the file for parameter struct and response struct.

  • Run the program for data
    go run main.go
    

Documentation

Index

Constants

View Source
const (
	CalAPI = "https://calendarific.com/api/v2/holidays?"
)

The API URL to get all the holidays

Variables

This section is empty.

Functions

This section is empty.

Types

type CalParameters

type CalParameters struct {
	ApiKey   string `url:"api_key,omitempty"`
	Country  string `url:"country,omitempty"`
	Year     int32  `url:"year,omitempty"`
	Day      int32  `url:"day,omitempty"`
	Month    int32  `url:"month,omitempty"`
	Location string `url:"location,omitempty"`
	Type     string `url:"type,omitempty"`
	Language string `url:"language,omitempty"`
	Uuid     bool   `url:"uuid,omitempty"`
}

Calendarific Parameters

func (*CalParameters) CalData

func (p *CalParameters) CalData() (*CalResponse, error)

Request the data from Calendarific

type CalResponse

type CalResponse struct {
	Meta struct {
		Code int `json:"code"`
	} `json:"meta"`
	Response struct {
		Holidays []struct {
			Name        string `json:"name"`
			Description string `json:"description"`
			Date        struct {
				Iso      string `json:"iso"`
				Datetime struct {
					Year  int `json:"year"`
					Month int `json:"month"`
					Day   int `json:"day"`
				} `json:"datetime"`
			} `json:"date"`
			Type      []string    `json:"type"`
			Locations string      `json:"locations"`
			States    interface{} `json:"states"` // sometimes its a struct, sometime its a string, so use interface
		} `json:"holidays"`
	} `json:"response"`
}

Calendarific Response

type States

type States []struct {
	ID        int         `json:"id"`
	Abbrev    string      `json:"abbrev"`
	Name      string      `json:"name"`
	Exception interface{} `json:"exception"`
	Iso       string      `json:"iso"`
}

We don't use this struct, since the states response json is not always a JSON it is sometimes a string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL