• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang webc.Context类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/cagnosolutions/webc.Context的典型用法代码示例。如果您正苦于以下问题:Golang Context类的具体用法?Golang Context怎么用?Golang Context使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了Context类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: reloadTemplates

func reloadTemplates(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	if r.FormValue("user") == "admin" && r.FormValue("pass") == "admin" {
		ts.Load()
		c.SetFlash("alertSuccess", "Successfully reloaded templates")
	}
	http.Redirect(w, r, "/", 303)
	return
}
开发者ID:cagnosolutions,项目名称:webc,代码行数:8,代码来源:main.go


示例2: homeController

func homeController(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	msgK, msgV := c.GetFlash()
	ts.Render(w, "index.tmpl", tmpl.Model{
		msgK:    msgV,
		"name":  "Greg",
		"age":   28,
		"email": "[email protected]",
		"data":  "bubb hghb hghgv bj hbkjb jhb jhbjh bhjb jhb jhb jhbj bjk bjhb jhbj hbjhbjh jhb Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.",
	})
}
开发者ID:cagnosolutions,项目名称:webc,代码行数:10,代码来源:main.go


示例3: AddConnection

// POST add new db connection
func AddConnection(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	var connection map[string]string
	config.GetAs("connections", r.FormValue("name"), &connection)
	if connection == nil {
		println(3)
		connection = make(map[string]string)
	}
	connection["address"] = r.FormValue("address")
	connection["token"] = r.FormValue("token")
	config.Set("connections", r.FormValue("name"), connection)
	c.SetFlash("alertSuccess", "Successfully added connection")
	http.Redirect(w, r, "/", 303)
	return
}
开发者ID:gregpechiro,项目名称:dbdbClient,代码行数:15,代码来源:main.go


示例4: Connect

// GET connect to DB
func Connect(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	var connection map[string]string
	if config.GetAs("connections", c.GetPathVar("db"), &connection) {
		if address, ok := connection["address"]; ok && address != "" {
			if rpc.Connect(address, connection["token"]) {
				c.SetFlash("alertSuccess", "Successfully connected to database")
				c.Set("db", c.GetPathVar("db"))
				http.Redirect(w, r, "/", 303)
				return
			}
		}
	}
	c.SetFlash("alertError", "Error connecting to the database")
	http.Redirect(w, r, "/", 303)
	return
}
开发者ID:gregpechiro,项目名称:dbdbClient,代码行数:17,代码来源:main.go


示例5: SaveStore

// POST add store to connected DB
func SaveStore(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	if !rpc.Alive() {
		http.Redirect(w, r, "/", 303)
		c.SetFlash("alertError", "Error no connection to a database")
		return
	}
	if c.Get("db") == nil || c.Get("db").(string) == "" {
		http.Redirect(w, r, "/disconnect", 303)
		return
	}
	name := r.FormValue("name")
	if ok := rpc.AddStore(name); ok {
		c.SetFlash("alertSuccess", "Successfully saved store")
	} else {
		c.SetFlash("alertError", "Error saving store")
	}
	http.Redirect(w, r, "/", 303)
	return
}
开发者ID:gregpechiro,项目名称:dbdbClient,代码行数:20,代码来源:main.go


示例6: SaveConnection

// POST update existing DB connection
func SaveConnection(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	var connection map[string]string
	ok := config.GetAs("connections", r.FormValue("name"), &connection)
	if r.FormValue("name") != r.FormValue("oldName") {
		if ok {
			c.SetFlash("alertError", "Error connection name already exists")
			http.Redirect(w, r, "/", 303)
			return
		}
		config.Del("connections", r.FormValue("oldName"))
	}
	if connection == nil {
		connection = make(map[string]string)
	}
	connection["address"] = r.FormValue("address")
	connection["token"] = r.FormValue("token")
	config.Set("connections", r.FormValue("name"), connection)
	c.SetFlash("alertSuccess", "Successfully updated connection")
	http.Redirect(w, r, "/", 303)
	return
}
开发者ID:gregpechiro,项目名称:dbdbClient,代码行数:22,代码来源:main.go


示例7: EraseDB

func EraseDB(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	if !rpc.Alive() {
		http.Redirect(w, r, "/", 303)
		c.SetFlash("alertError", "Error no connection to a database")
		return
	}
	if c.Get("db") == nil || c.Get("db").(string) == "" {
		http.Redirect(w, r, "/disconnect", 303)
		return
	}
	rpc.ClearAll()
	c.SetFlash("alertSuccess", "Successfully erased database")
	http.Redirect(w, r, "/", 303)
	return
}
开发者ID:gregpechiro,项目名称:dbdbClient,代码行数:15,代码来源:main.go


示例8: Root

// GET render all saved DBs or show currently cinnected DB
func Root(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	msgk, msgv := c.GetFlash()

	// Not connected display all DBs
	if !rpc.Alive() {
		ts.Render(w, "index.tmpl", tmpl.Model{
			msgk:    msgv,
			"dbs":   GetSavedDBs(),
			"conns": config.GetStore("connections"),
		})
		return
	}

	if c.Get("db") == nil || c.Get("db").(string) == "" {
		http.Redirect(w, r, "/disconnect", 303)
		return
	}
	ts.Render(w, "db.tmpl", tmpl.Model{
		msgk:     msgv,
		"db":     c.Get("db"),
		"stores": rpc.GetAllStoreStats(),
	})
	return
}
开发者ID:gregpechiro,项目名称:dbdbClient,代码行数:25,代码来源:main.go


示例9: NewRecord

// GET render empty record for specified store from connected DB
func NewRecord(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	if !rpc.Alive() {
		http.Redirect(w, r, "/", 303)
		c.SetFlash("alertError", "Error no connection to a database")
		return
	}
	if c.Get("db") == nil || c.Get("db").(string) == "" {
		http.Redirect(w, r, "/disconnect", 303)
		return
	}
	msgk, msgv := c.GetFlash()
	ts.Render(w, "record.tmpl", tmpl.Model{
		msgk:        msgv,
		"db":        c.Get("db"),
		"stores":    rpc.GetAllStoreStats(),
		"storeName": c.GetPathVar("store"),
		"record":    "",
	})
	return
}
开发者ID:gregpechiro,项目名称:dbdbClient,代码行数:21,代码来源:main.go


示例10: DelStore

// POST delete store from connected DB
func DelStore(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	if !rpc.Alive() {
		http.Redirect(w, r, "/", 303)
		c.SetFlash("alertError", "Error no connection to a database")
		return
	}
	if c.Get("db") == nil || c.Get("db").(string) == "" {
		http.Redirect(w, r, "/disconnect", 303)
		return
	}
	if !rpc.DelStore(c.GetPathVar("store")) {
		c.SetFlash("alertError", "Error deleteing store")
	} else {
		c.SetFlash("alertSuccess", "Successfully deleted store")
	}
	http.Redirect(w, r, "/", 303)
	return
}
开发者ID:gregpechiro,项目名称:dbdbClient,代码行数:19,代码来源:main.go


示例11: SaveSearch

// POST save search made on store
func SaveSearch(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	if !rpc.Alive() {
		http.Redirect(w, r, "/", 303)
		c.SetFlash("alertError", "Error no connection to a database")
		return
	}
	if c.Get("db") == nil || c.Get("db").(string) == "" {
		http.Redirect(w, r, "/disconnect", 303)
		return
	}
	var savedSearch map[string]map[string]string

	config.GetAs("search", c.Get("db").(string), &savedSearch)
	if savedSearch == nil {
		savedSearch = make(map[string]map[string]string)
	}
	if savedSearch[c.GetPathVar("store")] == nil {
		savedSearch[c.GetPathVar("store")] = make(map[string]string)
	}
	savedSearch[c.GetPathVar("store")][r.FormValue("name")] = r.FormValue("search")
	config.Set("search", c.Get("db").(string), savedSearch)
	c.SetFlash("alertSuccess", "Successfully saved search")
	http.Redirect(w, r, fmt.Sprintf("/%s", c.GetPathVar("store")), 303)
	return
}
开发者ID:gregpechiro,项目名称:dbdbClient,代码行数:26,代码来源:main.go


示例12: admin

func admin(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	c.CheckAuth(w, r, "admin", "/")
	fmt.Fprintf(w, "page: user, addr: %s, user-agent: %s", r.RemoteAddr, r.UserAgent())
	return
}
开发者ID:cagnosolutions,项目名称:webc,代码行数:5,代码来源:main.go


示例13: Store

// GET render specified store from specified DB
func Store(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	if !rpc.Alive() {
		http.Redirect(w, r, "/", 303)
		c.SetFlash("alertError", "Error no connection to a database")
		return
	}
	if c.Get("db") == nil || c.Get("db").(string) == "" {
		http.Redirect(w, r, "/disconnect", 303)
		return
	}
	msgk, msgv := c.GetFlash()
	if !rpc.HasStore(c.GetPathVar("store")) {
		c.SetFlash("alertError", "Invalid store")
		http.Redirect(w, r, fmt.Sprintf("/%s", c.GetPathVar("db")), 303)
		return
	}
	ts.Render(w, "store.tmpl", tmpl.Model{
		msgk:          msgv,
		"savedSearch": GetSavedSearches(c.Get("db").(string), c.GetPathVar("store")),
		"db":          c.Get("db"),
		"stores":      rpc.GetAllStoreStats(),
		"store":       rpc.GetAll(c.GetPathVar("store")),
		"storeName":   c.GetPathVar("store"),
		"query":       GetSavedSearch(c.Get("db").(string), c.GetPathVar("store"), r.FormValue("query")),
	})
	return
}
开发者ID:gregpechiro,项目名称:dbdbClient,代码行数:28,代码来源:main.go


示例14: protected

func protected(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	slug := c.GetPathVar("slug")
	c.CheckAuth(w, r, "driver", "/"+slug)
	fmt.Fprintf(w, "You are authorized to view page %s", slug)
}
开发者ID:cagnosolutions,项目名称:webc,代码行数:5,代码来源:main.go


示例15: adminLogin

func adminLogin(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	c.Login("admin")
	c.SetFlash("success", "You are now logged into. Enjoy")
	http.Redirect(w, r, "/admin", 303)
}
开发者ID:cagnosolutions,项目名称:webc,代码行数:5,代码来源:main.go


示例16: Record

// GET render specified record from specified store in connected DB
func Record(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	if !rpc.Alive() {
		http.Redirect(w, r, "/", 303)
		c.SetFlash("alertError", "Error no connection to a database")
		return
	}
	if c.Get("db") == nil || c.Get("db").(string) == "" {
		http.Redirect(w, r, "/disconnect", 303)
		return
	}
	msgk, msgv := c.GetFlash()
	record := rpc.Get(c.GetPathVar("store"), GetId(c.GetPathVar("record")))
	if record == nil {
		c.SetFlash("alertError", "Invalid Record")
		http.Redirect(w, r, fmt.Sprintf("/%s/%s", c.GetPathVar("db"), c.GetPathVar("store")), 303)
		return
	}
	ts.Render(w, "record.tmpl", tmpl.Model{
		msgk:        msgv,
		"db":        c.Get("db"),
		"stores":    rpc.GetAllStoreStats(),
		"storeName": c.GetPathVar("store"),
		"record":    record,
	})
	return
}
开发者ID:gregpechiro,项目名称:dbdbClient,代码行数:27,代码来源:main.go


示例17: DelRecord

// POST delete record from specified store in connected DB
func DelRecord(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	if !rpc.Alive() {
		http.Redirect(w, r, "/", 303)
		c.SetFlash("alertError", "Error no connection to a database")
		return
	}
	if c.Get("db") == nil || c.Get("db").(string) == "" {
		http.Redirect(w, r, "/disconnect", 303)
		return
	}
	rpc.Del(c.GetPathVar("store"), GetId(c.GetPathVar("record")))
	c.SetFlash("alertSuccess", "Successfully deleted record")
	http.Redirect(w, r, fmt.Sprintf("/%s", c.GetPathVar("store")), 303)
	return
}
开发者ID:gregpechiro,项目名称:dbdbClient,代码行数:16,代码来源:main.go


示例18: UploadRecords

// POST upload .json file of records to add to store
func UploadRecords(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	if !rpc.Alive() {
		http.Redirect(w, r, "/", 303)
		c.SetFlash("alertError", "Error no connection to a database")
		return
	}
	if c.Get("db") == nil || c.Get("db").(string) == "" {
		http.Redirect(w, r, "/disconnect", 303)
		return
	}
	r.ParseMultipartForm(32 << 20) // 32 MB
	file, handler, err := r.FormFile("data")
	if err != nil || len(handler.Header["Content-Type"]) < 1 {
		fmt.Println(err)
		c.SetFlash("alertError", "Error uploading file")
		http.Redirect(w, r, "/"+c.GetPathVar("store")+"/import", 303)
		return
	}
	defer file.Close()
	var m []map[string]interface{}
	switch handler.Header["Content-Type"][0] {
	case "application/json":
		dec := json.NewDecoder(file)
		err = dec.Decode(&m)
	case "text/csv":
		m, err = DecodeCSV(file)
	default:
		c.SetFlash("alertError", "Error uploading file")
		http.Redirect(w, r, "/"+c.GetPathVar("store")+"/import", 303)
		return
	}

	if err != nil {
		fmt.Println(err)
		c.SetFlash("alertError", "Error uploading file")
		http.Redirect(w, r, "/"+c.GetPathVar("store")+"/import", 303)
		return
	}

	for _, doc := range m {
		SanitizeMap(&doc)
		rpc.Add(c.GetPathVar("store"), doc)
	}
	c.SetFlash("alertSuccess", "Successfully imported data")
	http.Redirect(w, r, "/"+c.GetPathVar("store"), 303)
	return
}
开发者ID:gregpechiro,项目名称:dbdbClient,代码行数:48,代码来源:main.go


示例19: DelConnection

// POST delete saved DB connection
func DelConnection(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	config.Del("connections", c.GetPathVar("db"))
	c.SetFlash("alertSuccess", "Successfully deleted connection")
	http.Redirect(w, r, "/", 303)
	return
}
开发者ID:gregpechiro,项目名称:dbdbClient,代码行数:7,代码来源:main.go


示例20: adminAdd

func adminAdd(w http.ResponseWriter, r *http.Request, c *webc.Context) {
	c.CheckAuth(w, r, "admin", "/")
	fmt.Fprintf(w, "User Add Page")
}
开发者ID:cagnosolutions,项目名称:webc,代码行数:4,代码来源:main.go



注:本文中的github.com/cagnosolutions/webc.Context类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang anchnet-go.Client类代码示例发布时间:2022-05-24
下一篇:
Golang web.Context类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap