From d76662791f9d8c4ad4b60a4d69afa1b98c476e91 Mon Sep 17 00:00:00 2001 From: quest Date: Sun, 24 Jan 2016 16:47:19 -0800 Subject: [PATCH] Added support for GitHub, Docker Hub, and Stack Overflow --- cmd/search.go | 2 +- providers/dockerhub/dockerhub.go | 21 +++++++++++++++++++++ providers/github/github.go | 21 +++++++++++++++++++++ providers/stackoverflow/stackoverflow.go | 21 +++++++++++++++++++++ s.go | 3 +++ 5 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 providers/dockerhub/dockerhub.go create mode 100644 providers/github/github.go create mode 100644 providers/stackoverflow/stackoverflow.go diff --git a/cmd/search.go b/cmd/search.go index d471a87..281c9f1 100644 --- a/cmd/search.go +++ b/cmd/search.go @@ -11,7 +11,7 @@ import ( const ( appName = "s" - version = "0.1.2" + version = "0.1.3" ) // Flag variables diff --git a/providers/dockerhub/dockerhub.go b/providers/dockerhub/dockerhub.go new file mode 100644 index 0000000..139b79f --- /dev/null +++ b/providers/dockerhub/dockerhub.go @@ -0,0 +1,21 @@ +package dockerhub + +import ( + "fmt" + "net/url" + + "github.com/zquestz/s/providers" +) + +func init() { + providers.AddProvider("dockerhub", &DockerHubProvider{}) +} + +// DockerHubProvider adheres to the Provider interface. +type DockerHubProvider struct { +} + +// BuildURI generates a search URL for Docker Hub. +func (p *DockerHubProvider) BuildURI(q string) string { + return fmt.Sprintf("https://hub.docker.com/search/?q=%s", url.QueryEscape(q)) +} diff --git a/providers/github/github.go b/providers/github/github.go new file mode 100644 index 0000000..246bb2b --- /dev/null +++ b/providers/github/github.go @@ -0,0 +1,21 @@ +package github + +import ( + "fmt" + "net/url" + + "github.com/zquestz/s/providers" +) + +func init() { + providers.AddProvider("github", &GitHubProvider{}) +} + +// GitHubProvider adheres to the Provider interface. +type GitHubProvider struct { +} + +// BuildURI generates a search URL for GitHub. +func (p *GitHubProvider) BuildURI(q string) string { + return fmt.Sprintf("https://github.com/search?utf8=✓&q=%s", url.QueryEscape(q)) +} diff --git a/providers/stackoverflow/stackoverflow.go b/providers/stackoverflow/stackoverflow.go new file mode 100644 index 0000000..df42028 --- /dev/null +++ b/providers/stackoverflow/stackoverflow.go @@ -0,0 +1,21 @@ +package stackoverflow + +import ( + "fmt" + "net/url" + + "github.com/zquestz/s/providers" +) + +func init() { + providers.AddProvider("stackoverflow", &StackOverflowProvider{}) +} + +// StackOverflowProvider adheres to the Provider interface. +type StackOverflowProvider struct { +} + +// BuildURI generates a search URL for Stack Overflow. +func (p *StackOverflowProvider) BuildURI(q string) string { + return fmt.Sprintf("http://stackoverflow.com/search?q=%s", url.QueryEscape(q)) +} diff --git a/s.go b/s.go index a034113..2198b56 100644 --- a/s.go +++ b/s.go @@ -7,9 +7,12 @@ import ( // Load necessary providers. _ "github.com/zquestz/s/providers/amazon" _ "github.com/zquestz/s/providers/bing" + _ "github.com/zquestz/s/providers/dockerhub" _ "github.com/zquestz/s/providers/duckduckgo" + _ "github.com/zquestz/s/providers/github" _ "github.com/zquestz/s/providers/google" _ "github.com/zquestz/s/providers/reddit" + _ "github.com/zquestz/s/providers/stackoverflow" _ "github.com/zquestz/s/providers/twitter" _ "github.com/zquestz/s/providers/wikipedia" _ "github.com/zquestz/s/providers/yahoo"