From 590f928c1eac5af6fbcac2a1f280eff23ad29e12 Mon Sep 17 00:00:00 2001 From: tukejonny Date: Sun, 27 Aug 2017 09:26:47 +0900 Subject: [PATCH] =?UTF-8?q?Context=E3=81=8C=E5=85=AC=E9=96=8B=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84=E3=81=9F=E3=82=81?= =?UTF-8?q?=E3=81=AB=E3=83=91=E3=83=83=E3=82=B1=E3=83=BC=E3=82=B8=E5=A4=96?= =?UTF-8?q?=E3=81=8B=E3=82=89=E3=82=B3=E3=83=B3=E3=83=86=E3=82=AD=E3=82=B9?= =?UTF-8?q?=E3=83=88=E3=82=92=E6=B8=A1=E3=81=9B=E3=81=AA=E3=81=8F=E3=81=AA?= =?UTF-8?q?=E3=81=A3=E3=81=A6=E3=81=84=E3=81=9F=E3=83=90=E3=82=B0=E3=82=92?= =?UTF-8?q?=E4=BF=AE=E6=AD=A3.=E3=81=BE=E3=81=9F=E3=80=81init=E9=96=A2?= =?UTF-8?q?=E6=95=B0=E3=81=AF=E8=A4=87=E6=95=B0=E6=9B=B8=E3=81=8F=E3=81=93?= =?UTF-8?q?=E3=81=A8=E3=81=8C=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AA=E3=81=AE=E3=81=A7=E3=80=81=E7=99=BB=E9=8C=B2=E6=BC=8F?= =?UTF-8?q?=E3=82=8C=E3=81=AE=E3=81=AA=E3=81=84=E3=82=88=E3=81=86,=20?= =?UTF-8?q?=E5=90=84=20.go=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=81=AB?= =?UTF-8?q?=E5=88=86=E5=89=B2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api.go | 13 ++++--------- events.go | 8 ++++++-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/api.go b/api.go index 2b47c72..40efc53 100644 --- a/api.go +++ b/api.go @@ -9,8 +9,8 @@ type apiClient interface { GetAPIData() interface{} } -type apiContext map[string]interface{} -type apiClientFactory func(ctx apiContext) apiClient +type APIContext map[string]interface{} +type apiClientFactory func(ctx APIContext) apiClient var apiClientFactories = make(map[string]apiClientFactory) @@ -27,12 +27,7 @@ func registerAPIClient(name string, factory apiClientFactory) { apiClientFactories[name] = factory } -// この関数はパッケージがimportされた時に呼び出されます -func init() { - registerAPIClient("events", newEventsAPIClient) -} - -func newAPIClient(name string, ctx apiContext) apiClient { +func newAPIClient(name string, ctx APIContext) apiClient { clientFactory, ok := apiClientFactories[name] if !ok { log.Panicf("Invalid API Client name!") @@ -41,7 +36,7 @@ func newAPIClient(name string, ctx apiContext) apiClient { return clientFactory(ctx) } -func GetUrl(name string, ctx apiContext) string { +func GetUrl(name string, ctx APIContext) string { client := newAPIClient(name, ctx) return client.GetUrl() } diff --git a/events.go b/events.go index b8aa8c2..a0d9a99 100644 --- a/events.go +++ b/events.go @@ -9,15 +9,19 @@ import ( ) type eventsAPIClient struct { - Ctx apiContext + Ctx APIContext } -func newEventsAPIClient(ctx apiContext) apiClient { +func newEventsAPIClient(ctx APIContext) apiClient { return &eventsAPIClient{ Ctx: ctx, } } +func init() { + registerAPIClient("events", newEventsAPIClient) +} + func (client *eventsAPIClient) GetUrl() string { now := time.Now().Unix()