本文整理汇总了Golang中github.com/labstack/echo.Context.String方法的典型用法代码示例。如果您正苦于以下问题:Golang Context.String方法的具体用法?Golang Context.String怎么用?Golang Context.String使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/labstack/echo.Context
的用法示例。
在下文中一共展示了Context.String方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: saveEquipType
func saveEquipType(c *echo.Context) error {
id, iderr := strconv.Atoi(c.Param("id"))
if iderr != nil {
return c.String(http.StatusNotAcceptable, "Invalid ID")
}
et := new(EquipType)
if binderr := c.Bind(et); binderr != nil {
log.Println(binderr.Error())
return binderr
}
//log.Println(et)
_, err := ExecDb(db,
`update equip_type
set name=$2,
is_consumable=$3,
is_asset=$4
where id=$1`,
id,
et.Name,
et.Consumable,
et.Asset)
if err != nil {
log.Println(err.Error())
}
return c.JSON(http.StatusOK, et)
}
示例2: deleteBot
// deleteBot получает команду от веб-клиента (удалить бота) и перенаправляет ее менеджеру ботов
func deleteBot(c *echo.Context) error {
id := c.Param("id")
action := "delete"
MB.SendActionToBot(id, action, nil)
return c.String(http.StatusOK, "ok\n")
}
示例3: upload
func upload(c *echo.Context) error {
req := c.Request()
req.ParseMultipartForm(16 << 20) // Max memory 16 MiB
// Read form fields
name := c.Form("name")
email := c.Form("email")
// Read files
files := req.MultipartForm.File["files"]
for _, f := range files {
// Source file
src, err := f.Open()
if err != nil {
return err
}
defer src.Close()
// Destination file
dst, err := os.Create(f.Filename)
if err != nil {
return err
}
defer dst.Close()
if _, err = io.Copy(dst, src); err != nil {
return err
}
}
return c.String(http.StatusOK, "Thank You! %s <%s>, %d files uploaded successfully.",
name, email, len(files))
}
示例4: RemoveTodo
func RemoveTodo(c echo.Context) error {
id := c.Param("id")
tododao.DeleteTodo(id)
return c.String(http.StatusOK, "")
}
示例5: login
// Expects username & password to be passed as JSON in the POST body
// This is how Ember does it.
func (s *APIServer) login(c echo.Context) error {
a := new(AuthInfo)
if err := c.Bind(a); err != nil {
return err
}
dbuser, err := s.DBH.GetUserByEmail(a.Username)
if err == nil {
//if bcrypt.CompareHashAndPassword([]byte(dbuser.Password), []byte(a.Password)) == nil {
token := jwt.New(jwt.SigningMethodHS256)
// Set claims
claims := token.Claims.(jwt.MapClaims)
claims["name"] = dbuser.Email
claims["admin"] = false
claims["exp"] = time.Now().Add(time.Hour * 72).Unix()
// Generate encoded token and send it as response.
t, err := token.SignedString([]byte("secret"))
if err != nil {
return err
}
return c.JSON(http.StatusOK, map[string]string{
"token": t,
})
//}
}
logrus.Infof("Unknown user or bad password for: %s", a.Username)
return c.String(http.StatusUnauthorized, "Bad username or password")
}
示例6: Index
func Index(c *echo.Context) error {
authCookie, err := c.Request().Cookie("testcook")
logrus.Infof(">>> cooki: %+v, err: %+v", authCookie, err)
dbconn := c.Get("db").(*mgo.Database)
counts := dbconn.C("counts")
if err := counts.Insert(&models.TestStruct{"index"}); err != nil {
c.String(500, fmt.Sprintf("broken: %s", err.Error()))
return nil
}
t, err := template.ParseFiles("static/html/layout.html", "static/html/greet.html", "static/html/mainPage.html")
if err != nil {
c.String(500, fmt.Sprintf("broken: %s", err.Error()))
return nil
}
loggedIn := false
user, ok := c.Get("user").(models.Account)
if ok {
loggedIn = user.Username != ""
}
args := map[string]interface{}{
"Username": user.Username,
"LoggedIn": loggedIn,
"Logout": fmt.Sprintf("http://username:[email protected]%s", viper.GetString("base_uri"))}
t.Execute(c.Response(), args)
return nil
}
示例7: statusHandler
func (tl *TeamLeader) statusHandler(c *echo.Context) error {
infos := make(map[string]interface{})
infos["Version"] = "0.001"
// utils.WriteJson(c, http.StatusOK, infos)
c.String(http.StatusOK, "Hello World")
return nil
}
示例8: login
func login(c *echo.Context) error {
l := new(loginCreds)
err := c.Bind(&l)
if err != nil {
log.Println("Bind Error:", err.Error())
}
//log.Println("Login Credentials", l)
sqlResult, _ := SQLMap(db,
`select u.username,u.role,u.site,s.name as sitename
from users u
left outer join site s on (s.id=u.site)
where u.username=$1 and u.passwd=$2`,
l.Username,
l.Password)
log.Println("SQLResult", sqlResult)
if len(sqlResult) == 1 {
r := new(loginResponse)
r.Username = l.Username
r.Role = sqlResult[0]["role"]
r.Token = "98023840238402840"
r.Site = sqlResult[0]["site"]
r.SiteName = sqlResult[0]["sitename"]
return c.JSON(http.StatusOK, r)
} else {
return c.String(http.StatusUnauthorized, "invalid")
}
}
示例9: Welcome
func Welcome(c *echo.Context) error {
session, err := mgo.Dial("localhost")
if err != nil {
panic(err)
}
defer session.Close()
mongo := session.DB("welcome").C("welcomes")
wm := models.Welcome{
Id: "123456",
Message: "Hello world",
}
err = mongo.Insert(&wm)
if err != nil {
panic(err)
}
result := models.Welcome{}
err = mongo.Find(bson.M{"id": "123456"}).One(&result)
if err != nil {
panic(err)
}
return c.String(http.StatusOK, result.Message)
}
示例10: saveSite
func saveSite(c *echo.Context) error {
id, iderr := strconv.Atoi(c.Param("id"))
if iderr != nil {
return c.String(http.StatusNotAcceptable, "Invalid ID")
}
site := new(SiteType)
if binderr := c.Bind(site); binderr != nil {
log.Println(binderr.Error())
return binderr
}
log.Println(site)
_, err := ExecDb(db,
`update site
set name=$2,
address=$3,
phone=$4,
contactname=$5
where id=$1`,
id,
site.Name,
site.Address,
site.Phone,
site.ContactName)
if err != nil {
log.Println(err.Error())
}
return c.JSON(http.StatusOK, site)
}
示例11: largeUnreported
func largeUnreported(c *echo.Context) error {
data, err := data.Asset("LargeCommercialBuildingsUnreported.json")
if err != nil {
genericError(c)
return err
}
return c.String(http.StatusOK, string(data))
}
示例12: Move
func Move(c *echo.Context) error {
alpha, _ := strconv.ParseInt(c.Param("alpha"), 10, 64)
beta, _ := strconv.ParseInt(c.Param("beta"), 10, 64)
MoveMouse(Orientation{int(alpha), int(beta)}.ToPixels(90, 90))
return c.String(http.StatusOK, "Hello")
}
示例13: Reset
func Reset(c *echo.Context) error {
err := demo.Reset()
if err != nil {
return c.String(1, err.Error())
}
return c.String(http.StatusOK, "reset success")
}
示例14: UserRegister
func UserRegister(c *echo.Context) error {
r, err := uhander.Register(c.Form("u"), "")
if err == nil {
return c.String(http.StatusOK, r)
} else {
return c.String(http.StatusInternalServerError, err.Error())
}
}
示例15: RenderStatic
func RenderStatic(c echo.Context) error {
a, err := Asset(fmt.Sprintf("static%s", c.P(0)))
if err != nil {
panic(err)
}
return c.String(http.StatusOK, string(a))
}