当前位置: 首页>>代码示例>>Golang>>正文


Golang Context.String方法代码示例

本文整理汇总了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)
}
开发者ID:steveoc64,项目名称:itrak.mmaint,代码行数:30,代码来源:handlers.go

示例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")
}
开发者ID:Dremalka,项目名称:SkynetPW_old,代码行数:8,代码来源:api.go

示例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))
}
开发者ID:jameswei,项目名称:kingtask,代码行数:32,代码来源:server.go

示例4: RemoveTodo

func RemoveTodo(c echo.Context) error {
	id := c.Param("id")

	tododao.DeleteTodo(id)

	return c.String(http.StatusOK, "")
}
开发者ID:bgdsh,项目名称:playground,代码行数:7,代码来源:todocontroller.go

示例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")
}
开发者ID:hobeone,项目名称:rss2go,代码行数:34,代码来源:auth.go

示例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
}
开发者ID:mikerjacobi,项目名称:echomongo,代码行数:31,代码来源:common.go

示例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
}
开发者ID:chrislusf,项目名称:netchan,代码行数:7,代码来源:leader.go

示例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")
	}
}
开发者ID:steveoc64,项目名称:itrak.mmaint,代码行数:29,代码来源:handlers.go

示例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)
}
开发者ID:unsign3d,项目名称:provago,代码行数:32,代码来源:welcome_middleware.go

示例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)
}
开发者ID:steveoc64,项目名称:itrak.mmaint,代码行数:32,代码来源:handlers.go

示例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))
}
开发者ID:wyantb,项目名称:site,代码行数:8,代码来源:server.go

示例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")
}
开发者ID:sreejithr,项目名称:GyroJoy,代码行数:8,代码来源:server.go

示例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")
}
开发者ID:Dataman-Cloud,项目名称:seckilling,代码行数:8,代码来源:handler.go

示例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())
	}
}
开发者ID:proudlily,项目名称:Auth_ser,代码行数:8,代码来源:funcs.go

示例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))
}
开发者ID:boundedinfinity,项目名称:bi-echo,代码行数:9,代码来源:renderers.go


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