mirror of
https://github.com/holidayapi/holidayapi-go.git
synced 2025-06-21 12:36:33 +00:00
fix:added models
This commit is contained in:
parent
6556bc0cb8
commit
f15ea6600e
8 changed files with 303 additions and 11 deletions
8
.idea/go-holidayapi.iml
generated
Normal file
8
.idea/go-holidayapi.iml
generated
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
6
.idea/misc.xml
generated
Normal file
6
.idea/misc.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="JavaScriptSettings">
|
||||||
|
<option name="languageLevel" value="ES6" />
|
||||||
|
</component>
|
||||||
|
</project>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/go-holidayapi.iml" filepath="$PROJECT_DIR$/.idea/go-holidayapi.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="$PROJECT_DIR$" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
242
.idea/workspace.xml
generated
Normal file
242
.idea/workspace.xml
generated
Normal file
|
@ -0,0 +1,242 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ChangeListManager">
|
||||||
|
<list default="true" id="881a79e0-96af-4431-ad87-340197b097ee" name="Default Changelist" comment="">
|
||||||
|
<change afterPath="$PROJECT_DIR$/custom_time.go" afterDir="false" />
|
||||||
|
<change afterPath="$PROJECT_DIR$/holidayapi_test.go" afterDir="false" />
|
||||||
|
<change beforePath="$PROJECT_DIR$/holidayapi.go" beforeDir="false" afterPath="$PROJECT_DIR$/holidayapi.go" afterDir="false" />
|
||||||
|
</list>
|
||||||
|
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||||
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
|
</component>
|
||||||
|
<component name="FileEditorManager">
|
||||||
|
<leaf>
|
||||||
|
<file pinned="false" current-in-tab="false">
|
||||||
|
<entry file="file://$PROJECT_DIR$/holidayapi.go">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="484">
|
||||||
|
<caret line="46" column="20" lean-forward="true" selection-start-line="46" selection-start-column="20" selection-end-line="46" selection-end-column="20" />
|
||||||
|
<folding>
|
||||||
|
<element signature="e#20#91#0" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</file>
|
||||||
|
<file pinned="false" current-in-tab="false">
|
||||||
|
<entry file="file://$PROJECT_DIR$/custom_time.go">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="252">
|
||||||
|
<caret line="14" selection-start-line="14" selection-end-line="14" />
|
||||||
|
<folding>
|
||||||
|
<element signature="e#20#49#0" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</file>
|
||||||
|
<file pinned="false" current-in-tab="true">
|
||||||
|
<entry file="file://$PROJECT_DIR$/holidayapi_test.go">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="252">
|
||||||
|
<caret line="14" column="5" lean-forward="true" selection-start-line="14" selection-start-column="5" selection-end-line="14" selection-end-column="5" />
|
||||||
|
<folding>
|
||||||
|
<element signature="e#20#48#0" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</file>
|
||||||
|
</leaf>
|
||||||
|
</component>
|
||||||
|
<component name="FileTemplateManagerImpl">
|
||||||
|
<option name="RECENT_TEMPLATES">
|
||||||
|
<list>
|
||||||
|
<option value="Go File" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="GOROOT" path="/snap/go/3540" />
|
||||||
|
<component name="Git.Settings">
|
||||||
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
|
</component>
|
||||||
|
<component name="IdeDocumentHistory">
|
||||||
|
<option name="CHANGED_PATHS">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/holidayapi.go" />
|
||||||
|
<option value="$PROJECT_DIR$/custom_time.go" />
|
||||||
|
<option value="$PROJECT_DIR$/holidayapi_test.go" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectConfigurationFiles">
|
||||||
|
<option name="files">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/.idea/go-holidayapi.iml" />
|
||||||
|
<option value="$PROJECT_DIR$/.idea/misc.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/.idea/modules.xml" />
|
||||||
|
<option value="$PROJECT_DIR$/.idea/vcs.xml" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectFrameBounds" extendedState="6">
|
||||||
|
<option name="y" value="-2" />
|
||||||
|
<option name="width" value="1080" />
|
||||||
|
<option name="height" value="1922" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectView">
|
||||||
|
<navigator proportions="" version="1">
|
||||||
|
<foldersAlwaysOnTop value="true" />
|
||||||
|
</navigator>
|
||||||
|
<panes>
|
||||||
|
<pane id="Scope" />
|
||||||
|
<pane id="ProjectPane">
|
||||||
|
<subPane>
|
||||||
|
<expand>
|
||||||
|
<path>
|
||||||
|
<item name="go-holidayapi" type="b2602c69:ProjectViewProjectNode" />
|
||||||
|
<item name="go-holidayapi" type="462c0819:PsiDirectoryNode" />
|
||||||
|
</path>
|
||||||
|
</expand>
|
||||||
|
<select />
|
||||||
|
</subPane>
|
||||||
|
</pane>
|
||||||
|
</panes>
|
||||||
|
</component>
|
||||||
|
<component name="PropertiesComponent">
|
||||||
|
<property name="DefaultGoTemplateProperty" value="Go File" />
|
||||||
|
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||||
|
<property name="go.gopath.indexing.explicitly.defined" value="true" />
|
||||||
|
<property name="go.import.settings.migrated" value="true" />
|
||||||
|
<property name="go.sdk.automatically.set" value="true" />
|
||||||
|
<property name="last_opened_file_path" value="$PROJECT_DIR$" />
|
||||||
|
<property name="nodejs_interpreter_path.stuck_in_default_project" value="undefined stuck path" />
|
||||||
|
<property name="nodejs_npm_path_reset_for_default_project" value="true" />
|
||||||
|
<property name="nodejs_package_manager_path" value="npm" />
|
||||||
|
</component>
|
||||||
|
<component name="RunDashboard">
|
||||||
|
<option name="ruleStates">
|
||||||
|
<list>
|
||||||
|
<RuleState>
|
||||||
|
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
|
||||||
|
</RuleState>
|
||||||
|
<RuleState>
|
||||||
|
<option name="name" value="StatusDashboardGroupingRule" />
|
||||||
|
</RuleState>
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="RunManager">
|
||||||
|
<configuration name="TestHoliday in github.com/gelleson/go-holidayapi" type="GoTestRunConfiguration" factoryName="Go Test" temporary="true" nameIsGenerated="true">
|
||||||
|
<module name="go-holidayapi" />
|
||||||
|
<working_directory value="$PROJECT_DIR$" />
|
||||||
|
<framework value="gotest" />
|
||||||
|
<kind value="PACKAGE" />
|
||||||
|
<package value="github.com/gelleson/go-holidayapi" />
|
||||||
|
<directory value="$PROJECT_DIR$/" />
|
||||||
|
<filePath value="$PROJECT_DIR$/" />
|
||||||
|
<pattern value="^TestHoliday$" />
|
||||||
|
<method v="2" />
|
||||||
|
</configuration>
|
||||||
|
<recent_temporary>
|
||||||
|
<list>
|
||||||
|
<item itemvalue="Go Test.TestHoliday in github.com/gelleson/go-holidayapi" />
|
||||||
|
</list>
|
||||||
|
</recent_temporary>
|
||||||
|
</component>
|
||||||
|
<component name="TestHistory">
|
||||||
|
<history-entry file="TestHoliday_in_github_com_gelleson_go-holidayapi - 2019.04.25 at 19h 03m 19s.xml">
|
||||||
|
<configuration name="TestHoliday in github.com/gelleson/go-holidayapi" configurationId="GoTestRunConfiguration" />
|
||||||
|
</history-entry>
|
||||||
|
<history-entry file="TestHoliday_in_github_com_gelleson_go-holidayapi - 2019.04.25 at 19h 03m 55s.xml">
|
||||||
|
<configuration name="TestHoliday in github.com/gelleson/go-holidayapi" configurationId="GoTestRunConfiguration" />
|
||||||
|
</history-entry>
|
||||||
|
<history-entry file="TestHoliday_in_github_com_gelleson_go-holidayapi - 2019.04.25 at 19h 05m 28s.xml">
|
||||||
|
<configuration name="TestHoliday in github.com/gelleson/go-holidayapi" configurationId="GoTestRunConfiguration" />
|
||||||
|
</history-entry>
|
||||||
|
<history-entry file="TestHoliday_in_github_com_gelleson_go-holidayapi - 2019.04.25 at 19h 05m 53s.xml">
|
||||||
|
<configuration name="TestHoliday in github.com/gelleson/go-holidayapi" configurationId="GoTestRunConfiguration" />
|
||||||
|
</history-entry>
|
||||||
|
<history-entry file="TestHoliday_in_github_com_gelleson_go-holidayapi - 2019.04.25 at 19h 06m 12s.xml">
|
||||||
|
<configuration name="TestHoliday in github.com/gelleson/go-holidayapi" configurationId="GoTestRunConfiguration" />
|
||||||
|
</history-entry>
|
||||||
|
<history-entry file="TestHoliday_in_github_com_gelleson_go-holidayapi - 2019.04.25 at 19h 06m 32s.xml">
|
||||||
|
<configuration name="TestHoliday in github.com/gelleson/go-holidayapi" configurationId="GoTestRunConfiguration" />
|
||||||
|
</history-entry>
|
||||||
|
<history-entry file="TestHoliday_in_github_com_gelleson_go-holidayapi - 2019.04.25 at 19h 07m 39s.xml">
|
||||||
|
<configuration name="TestHoliday in github.com/gelleson/go-holidayapi" configurationId="GoTestRunConfiguration" />
|
||||||
|
</history-entry>
|
||||||
|
<history-entry file="TestHoliday_in_github_com_gelleson_go-holidayapi - 2019.04.25 at 19h 08m 40s.xml">
|
||||||
|
<configuration name="TestHoliday in github.com/gelleson/go-holidayapi" configurationId="GoTestRunConfiguration" />
|
||||||
|
</history-entry>
|
||||||
|
<history-entry file="TestHoliday_in_github_com_gelleson_go-holidayapi - 2019.04.25 at 19h 11m 40s.xml">
|
||||||
|
<configuration name="TestHoliday in github.com/gelleson/go-holidayapi" configurationId="GoTestRunConfiguration" />
|
||||||
|
</history-entry>
|
||||||
|
<history-entry file="TestHoliday_in_github_com_gelleson_go-holidayapi - 2019.04.25 at 19h 13m 23s.xml">
|
||||||
|
<configuration name="TestHoliday in github.com/gelleson/go-holidayapi" configurationId="GoTestRunConfiguration" />
|
||||||
|
</history-entry>
|
||||||
|
</component>
|
||||||
|
<component name="ToolWindowManager">
|
||||||
|
<frame x="0" y="-2" width="1080" height="1922" extended-state="6" />
|
||||||
|
<editor active="true" />
|
||||||
|
<layout>
|
||||||
|
<window_info id="Favorites" side_tool="true" />
|
||||||
|
<window_info content_ui="combo" id="Project" order="0" type="SLIDING" weight="0.24951644" />
|
||||||
|
<window_info id="Structure" order="1" side_tool="true" weight="0.25" />
|
||||||
|
<window_info anchor="bottom" id="Docker" show_stripe_button="false" />
|
||||||
|
<window_info anchor="bottom" id="Database Changes" />
|
||||||
|
<window_info anchor="bottom" id="Version Control" />
|
||||||
|
<window_info anchor="bottom" id="Terminal" />
|
||||||
|
<window_info anchor="bottom" id="Event Log" side_tool="true" />
|
||||||
|
<window_info anchor="bottom" id="Message" order="0" />
|
||||||
|
<window_info anchor="bottom" id="Find" order="1" />
|
||||||
|
<window_info active="true" anchor="bottom" id="Run" order="2" visible="true" weight="0.32975113" />
|
||||||
|
<window_info anchor="bottom" id="Debug" order="3" weight="0.4" />
|
||||||
|
<window_info anchor="bottom" id="Cvs" order="4" weight="0.25" />
|
||||||
|
<window_info anchor="bottom" id="Inspection" order="5" weight="0.4" />
|
||||||
|
<window_info anchor="bottom" id="TODO" order="6" />
|
||||||
|
<window_info anchor="right" id="Database" />
|
||||||
|
<window_info anchor="right" id="Commander" internal_type="SLIDING" order="0" type="SLIDING" weight="0.4" />
|
||||||
|
<window_info anchor="right" id="Ant Build" order="1" weight="0.25" />
|
||||||
|
<window_info anchor="right" content_ui="combo" id="Hierarchy" order="2" weight="0.25" />
|
||||||
|
</layout>
|
||||||
|
</component>
|
||||||
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
|
<option name="version" value="1" />
|
||||||
|
</component>
|
||||||
|
<component name="editorHistoryManager">
|
||||||
|
<entry file="file://$PROJECT_DIR$/custom_time.go">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="252">
|
||||||
|
<caret line="14" selection-start-line="14" selection-end-line="14" />
|
||||||
|
<folding>
|
||||||
|
<element signature="e#20#49#0" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/holidayapi.go">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="484">
|
||||||
|
<caret line="46" column="20" lean-forward="true" selection-start-line="46" selection-start-column="20" selection-end-line="46" selection-end-column="20" />
|
||||||
|
<folding>
|
||||||
|
<element signature="e#20#91#0" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/holidayapi_test.go">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="252">
|
||||||
|
<caret line="14" column="5" lean-forward="true" selection-start-line="14" selection-start-column="5" selection-end-line="14" selection-end-column="5" />
|
||||||
|
<folding>
|
||||||
|
<element signature="e#20#48#0" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</component>
|
||||||
|
</project>
|
|
@ -2,6 +2,8 @@ package holidayapi
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
"github.com/simplereach/timeutils"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
|
@ -21,8 +23,27 @@ func NewV1(key string) *V1 {
|
||||||
return v1
|
return v1
|
||||||
}
|
}
|
||||||
|
|
||||||
func (v1 *V1) Holidays(args map[string]interface{}) (map[string]interface{}, error) {
|
type Respone struct {
|
||||||
var data map[string]interface{}
|
Status int32 `json:"status"`
|
||||||
|
Requests Request `json:"requests"`
|
||||||
|
Holidays []Holiday `json:"holidays"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Request struct {
|
||||||
|
Used int32 `json:"used"`
|
||||||
|
Available int32 `json:"available"`
|
||||||
|
Resets timeutils.Time `json:"resets"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Holiday struct {
|
||||||
|
Name string `json:"name"`
|
||||||
|
Date timeutils.Time `json:"date,omniempty"`
|
||||||
|
Observed timeutils.Time `json:"observed"`
|
||||||
|
Public bool `json:"public"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func (v1 *V1) Holidays(args map[string]string) (Respone, error) {
|
||||||
|
var data Respone
|
||||||
|
|
||||||
if _, ok := args["key"]; !ok {
|
if _, ok := args["key"]; !ok {
|
||||||
args["key"] = v1.Key
|
args["key"] = v1.Key
|
||||||
|
@ -31,13 +52,13 @@ func (v1 *V1) Holidays(args map[string]interface{}) (map[string]interface{}, err
|
||||||
params := url.Values{}
|
params := url.Values{}
|
||||||
|
|
||||||
for k, v := range args {
|
for k, v := range args {
|
||||||
params.Add(k, v.(string))
|
params.Add(k, v)
|
||||||
}
|
}
|
||||||
|
|
||||||
resp, err := http.Get(v1.Url + params.Encode())
|
resp, err := http.Get(v1.Url + params.Encode())
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return Respone{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
defer resp.Body.Close()
|
defer resp.Body.Close()
|
||||||
|
@ -45,17 +66,16 @@ func (v1 *V1) Holidays(args map[string]interface{}) (map[string]interface{}, err
|
||||||
body, err := ioutil.ReadAll(resp.Body)
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return Respone{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
json.Unmarshal([]byte(string(body)), &data)
|
err = json.Unmarshal(body, &data)
|
||||||
|
if err != nil {
|
||||||
|
return Respone{}, err
|
||||||
|
}
|
||||||
|
|
||||||
if resp.StatusCode != 200 {
|
if resp.StatusCode != 200 {
|
||||||
_, ok := data["error"]
|
return Respone{}, errors.New("Unknown error!")
|
||||||
|
|
||||||
if !ok {
|
|
||||||
data["error"] = "Unknown error."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return data, nil
|
return data, nil
|
||||||
|
|
1
holidayapi_test.go
Normal file
1
holidayapi_test.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package holidayapi
|
1
models.go
Normal file
1
models.go
Normal file
|
@ -0,0 +1 @@
|
||||||
|
package holidayapi
|
Loading…
Add table
Add a link
Reference in a new issue