summarylogtreecommitdiffstats
path: root/plugins.go
diff options
context:
space:
mode:
authorcrvv2017-06-29 10:29:43 +0000
committercrvv2017-06-29 10:29:43 +0000
commitfd09433a3106a1efcc685d61a91f9175f77cef61 (patch)
treeef64335bc5f618cefd4d5a14b0765a5ab057828c /plugins.go
parent50c32c397251d5b5029745d7e77820bb0e800306 (diff)
downloadaur-fd09433a3106a1efcc685d61a91f9175f77cef61.tar.gz
add plugin configuration in PKGBUILD
Diffstat (limited to 'plugins.go')
-rw-r--r--plugins.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/plugins.go b/plugins.go
new file mode 100644
index 000000000000..75d16ffff15e
--- /dev/null
+++ b/plugins.go
@@ -0,0 +1,61 @@
+package main
+
+import (
+ "encoding/json"
+ "fmt"
+ "io/ioutil"
+ "log"
+ "net/http"
+ "os"
+ "sort"
+)
+
+const URL = "https://caddyserver.com/api/download-page"
+
+type Plugin struct {
+ Name string
+ ImportPath string
+}
+type PluginList struct {
+ Plugins []Plugin `json:"plugins"`
+}
+
+func getPlugins() []Plugin {
+ resp, err := http.Get(URL)
+ if err != nil {
+ log.Fatal(err)
+ }
+ defer resp.Body.Close()
+ body, err := ioutil.ReadAll(resp.Body)
+ list := PluginList{}
+ err = json.Unmarshal(body, &list)
+ if err != nil {
+ log.Fatal(err)
+ }
+ return list.Plugins
+}
+func main() {
+ plugins := getPlugins()
+ sort.Slice(plugins, func(i, j int) bool {
+ return plugins[i].Name < plugins[j].Name
+ })
+ if len(os.Args) == 1 {
+ fmt.Println("plugins=(")
+ for _, plugin := range plugins {
+ fmt.Printf("# '%s'\n", plugin.Name)
+ }
+ fmt.Println(")")
+ return
+ }
+ pluginsMap := make(map[string]string)
+ for _, plugin := range plugins {
+ pluginsMap[plugin.Name] = plugin.ImportPath
+ }
+ for _, name := range os.Args[1:] {
+ path, ok := pluginsMap[name]
+ if !ok {
+ log.Fatalf("cannot find plugin %s\n", name)
+ }
+ fmt.Printf(`_ "%s"`+"\n", path)
+ }
+}