Пример #1
0
// 初始化core包。返回程序必要的变量。
func loadOptions() (*Options, error) {
	sql := "SELECT * FROM #options"
	rows, err := db.Query(true, sql)
	if err != nil {
		return nil, err
	}
	maps, err := fetch.MapString(false, rows)
	rows.Close()
	if err != nil {
		return nil, err
	}

	opt := &Options{}
	if err = opt.fromMaps(maps); err != nil {
		return nil, err
	}
	return opt, nil
}
Пример #2
0
// @api get /admin/api/tags 获取所有标签信息
// @apiGroup admin
//
// @apiRequest json
// @apiheader Authorization xxx
//
// @apiSuccess 200 OK
// @apiParam tags array 所有标签的列表
func adminGetTags(w http.ResponseWriter, r *http.Request) {
	sql := `SELECT m.{name}, m.{title}, m.{description}, m.{id},count(r.{tagID}) AS {count}
			FROM #tags AS m
			LEFT JOIN #relationships AS r ON m.{id}=r.{tagID}
			GROUP BY m.{id}`
	rows, err := db.Query(true, sql)
	if err != nil {
		logs.Error("getTags:", err)
		util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
		return
	}

	maps, err := fetch.MapString(false, rows)
	rows.Close()
	if err != nil {
		logs.Error("getTags:", err)
		util.RenderJSON(w, http.StatusInternalServerError, nil, nil)
		return
	}

	util.RenderJSON(w, http.StatusOK, map[string]interface{}{"tags": maps}, nil)
}