當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。