本文整理汇总了Golang中github.com/unrolled/render.Render.Text方法的典型用法代码示例。如果您正苦于以下问题:Golang Render.Text方法的具体用法?Golang Render.Text怎么用?Golang Render.Text使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/unrolled/render.Render
的用法示例。
在下文中一共展示了Render.Text方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: addPositionHandler
func addPositionHandler(formatter *render.Render, dispatcher queueDispatcher) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
payload, _ := ioutil.ReadAll(req.Body)
var newPositionCommand positionCommand
err := json.Unmarshal(payload, &newPositionCommand)
if err != nil {
formatter.Text(w, http.StatusBadRequest, "Failed to parse add position command.")
return
}
if !newPositionCommand.isValid() {
formatter.Text(w, http.StatusBadRequest, "Invalid position command.")
return
}
evt := dronescommon.PositionChangedEvent{
DroneID: newPositionCommand.DroneID,
Longitude: newPositionCommand.Longitude,
Latitude: newPositionCommand.Latitude,
Altitude: newPositionCommand.Altitude,
CurrentSpeed: newPositionCommand.CurrentSpeed,
HeadingCardinal: newPositionCommand.HeadingCardinal,
ReceivedOn: time.Now().Unix(),
}
dispatcher.DispatchMessage(evt)
formatter.JSON(w, http.StatusCreated, evt)
}
}
示例2: addTelemetryHandler
func addTelemetryHandler(formatter *render.Render, dispatcher queueDispatcher) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
payload, _ := ioutil.ReadAll(req.Body)
var newTelemetryCommand telemetryCommand
err := json.Unmarshal(payload, &newTelemetryCommand)
if err != nil {
formatter.Text(w, http.StatusBadRequest, "Failed to parse add telemetry command.")
return
}
if !newTelemetryCommand.isValid() {
formatter.Text(w, http.StatusBadRequest, "Invalid telemetry command.")
return
}
evt := dronescommon.TelemetryUpdatedEvent{
DroneID: newTelemetryCommand.DroneID,
RemainingBattery: newTelemetryCommand.RemainingBattery,
Uptime: newTelemetryCommand.Uptime,
CoreTemp: newTelemetryCommand.CoreTemp,
ReceivedOn: time.Now().Unix(),
}
fmt.Printf("Dispatching telemetry event for drone %s\n", newTelemetryCommand.DroneID)
dispatcher.DispatchMessage(evt)
formatter.JSON(w, http.StatusCreated, evt)
}
}
示例3: createMatchHandler
func createMatchHandler(formatter *render.Render, repo matchRepository) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
payload, _ := ioutil.ReadAll(req.Body)
var newMatchRequest newMatchRequest
err := json.Unmarshal(payload, &newMatchRequest)
if err != nil {
formatter.Text(w, http.StatusBadRequest, "Failed to parse match request")
return
}
if !newMatchRequest.isValid() {
formatter.Text(w, http.StatusBadRequest, "Invalid new match request")
return
}
newMatch := gogo.NewMatch(newMatchRequest.GridSize, newMatchRequest.PlayerBlack, newMatchRequest.PlayerWhite)
repo.addMatch(newMatch)
var mr newMatchResponse
mr.copyMatch(newMatch)
w.Header().Add("Location", "/matches/"+newMatch.ID)
formatter.JSON(w, http.StatusCreated, &mr)
}
}
示例4: addAlertHandler
func addAlertHandler(formatter *render.Render, dispatcher queueDispatcher) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
payload, _ := ioutil.ReadAll(req.Body)
var newAlertCommand alertCommand
err := json.Unmarshal(payload, &newAlertCommand)
if err != nil {
formatter.Text(w, http.StatusBadRequest, "Failed to parse add alert command.")
return
}
if !newAlertCommand.isValid() {
formatter.Text(w, http.StatusBadRequest, "Invalid alert command.")
return
}
evt := dronescommon.AlertSignalledEvent{
DroneID: newAlertCommand.DroneID,
FaultCode: newAlertCommand.FaultCode,
Description: newAlertCommand.Description,
ReceivedOn: time.Now().Unix(),
}
dispatcher.DispatchMessage(evt)
formatter.JSON(w, http.StatusCreated, evt)
}
}
示例5: homeHandler
func homeHandler(formatter *render.Render) http.HandlerFunc {
return func(w http.ResponseWriter, req *http.Request) {
formatter.Text(w, http.StatusOK, "Drones Sample - Event Processor see http://github.com/cloudnativego/drones-events")
}
}
示例6: ErrorMessageFunc
func ErrorMessageFunc(r *render.Render) ServePrimeFunc {
return func(w http.ResponseWriter, req *http.Request) {
// http.ServeFile(w,req,"DHUCourseChooseHTML/login.html")
r.Text(w, http.StatusOK, "Hello World!This is the error page of the website")
}
}