コード例 #1
0
ファイル: plugin_router.go プロジェクト: shawnps/wikifeat
// Returns the list of all enabled plugins
// Non-enabled plugins are not included
func getPluginList(w http.ResponseWriter, r *http.Request) {
	_, err := AuthUser(r)
	if err != nil {
		http.Error(w, err.Error(), http.StatusUnauthorized)
	}
	LogRequest(r)
	pluginList := fserv.GetEnabledPlugins()
	jsonList, err := json.Marshal(pluginList)
	if err != nil {
		LogError(err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
		return
	}
	w.Header().Set("Content-Type", "application/json")
	w.Write(jsonList)
}
コード例 #2
0
ファイル: router.go プロジェクト: rhinoman/wikifeat
// Opens up the index.html file and adds additional (mostly plugin) elements
func finishIndex(filename string) {
	log.Print("Finishing index file")

	fileReader, err := os.Open(filename)
	if err != nil {
		log.Fatal(err)
	}
	//Parse the html document
	doc, err := html.Parse(fileReader)
	if err != nil {
		log.Fatal(err)
	}
	//Find the HEAD
	var processNode func(*html.Node)
	processNode = func(node *html.Node) {
		if node.Type == html.ElementNode && node.Data == "head" {
			enabledPlugins := fserv.GetEnabledPlugins()
			for _, plugin := range enabledPlugins {
				name := plugin.Name
				css := plugin.Stylesheet
				if css != "" {
					path := "/app/plugin/" + name + "/resource/" + css
					//Construct a new link css node and add it to the head
					attributes := []html.Attribute{
						html.Attribute{Key: "rel", Val: "stylesheet"},
						html.Attribute{Key: "type", Val: "text/css"},
						html.Attribute{Key: "href", Val: path},
					}
					linkNode := html.Node{
						Type: html.ElementNode,
						Data: "link",
						Attr: attributes,
					}
					node.AppendChild(&linkNode)
				}
			}
		}
		for c := node.FirstChild; c != nil; c = c.NextSibling {
			processNode(c)
		}
	}
	processNode(doc)
	var b bytes.Buffer
	html.Render(&b, doc)
	indexHtml = b.String()
	fileReader.Close()
}