本文整理匯總了Golang中github.com/elos/gaia/services.Logger.Print方法的典型用法代碼示例。如果您正苦於以下問題:Golang Logger.Print方法的具體用法?Golang Logger.Print怎麽用?Golang Logger.Print使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/elos/gaia/services.Logger
的用法示例。
在下文中一共展示了Logger.Print方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: CommandWebGET
// Expects: the context to hold the authed user
func CommandWebGET(ctx context.Context, ws *websocket.Conn, logger services.Logger, db data.DB) {
u, ok := user.FromContext(ctx)
if !ok {
logger.Print("CommandWebGET Error: failed to retrieve user from context")
return
}
input := make(chan string)
output := make(chan string)
session := command.NewSession(
u, db, input, output,
func() {
log.Print("CommandWebGET bail")
close(output)
},
)
go session.Start()
go func() {
for {
var message string
err := websocket.Message.Receive(ws, &message)
if err != nil {
if err != io.EOF {
log.Printf("Read fail: %s", err)
}
close(output) // should this know about output
return
}
input <- message
}
}()
for o := range output {
err := websocket.Message.Send(ws, o)
if err != nil {
log.Printf("Write fail: %s", err)
return
}
}
}
示例2: ContextualizeCommandWebGET
func ContextualizeCommandWebGET(ctx context.Context, db data.DB, logger services.Logger) websocket.Handler {
return func(c *websocket.Conn) {
if err := c.Request().ParseForm(); err != nil {
logger.Print("Failure parsing form")
return
}
public := c.Request().Form.Get("public")
private := c.Request().Form.Get("private")
if public == "" || private == "" {
logger.Print("failed to retrieve credentials")
return
}
cred, err := access.Authenticate(db, public, private)
if err != nil {
logger.Print("failed to auth")
return
}
u, _ := cred.Owner(db)
CommandWebGET(user.NewContext(ctx, u), c, logger, db)
}
}
示例3: MobileLocationPOST
func MobileLocationPOST(ctx context.Context, w http.ResponseWriter, r *http.Request, l services.Logger, db data.DB) {
// Parse the form value
if err := r.ParseForm(); err != nil {
l.Printf("MobileLocationPOST Error: %s", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
// Altitude
alt := r.FormValue(altitudeParam)
if alt == "" {
http.Error(w, "You must specify an altitude", http.StatusBadRequest)
return
}
altitude, err := strconv.ParseFloat(alt, 64)
if err != nil {
http.Error(w, "Parsing altitude", http.StatusBadRequest)
return
}
// Latitude
lat := r.FormValue(latitudeParam)
if lat == "" {
http.Error(w, "You must specify a latitude", http.StatusBadRequest)
return
}
latitude, err := strconv.ParseFloat(lat, 64)
if err != nil {
http.Error(w, "Parsing latitude", http.StatusBadRequest)
return
}
// Longitude
lon := r.FormValue(longitudeParam)
if lon == "" {
http.Error(w, "You must specify an longitude", http.StatusBadRequest)
return
}
longitude, err := strconv.ParseFloat(lon, 64)
if err != nil {
http.Error(w, "Parsing longitude", http.StatusBadRequest)
return
}
// Retrieve the user this request was authenticated as
u, ok := user.FromContext(ctx)
if !ok { // This is certainly an issue, and should _never_ happen
l.Print("MobileLocationPOST Error: failed to retrieve user from context")
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
// Create location
loc := location.NewCoords(altitude, latitude, longitude)
loc.SetID(db.NewID())
loc.SetOwner(u)
now := loc.CreatedAt
e := models.NewEvent()
e.CreatedAt = now
e.SetID(db.NewID())
e.SetOwner(u)
e.Name = "Location Update"
e.SetLocation(loc)
e.Time = now
e.UpdatedAt = now
locationTag, err1 := tag.ForName(db, u, tag.Location)
updateTag, err2 := tag.ForName(db, u, tag.Update)
mobileTag, err3 := tag.ForName(db, u, tag.Mobile)
if err1 != nil || err2 != nil || err3 != nil {
l.Printf("MobileLocationPOST Error: %s", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
e.IncludeTag(locationTag)
e.IncludeTag(updateTag)
e.IncludeTag(mobileTag)
if err = db.Save(loc); err != nil {
l.Printf("MobileLocationPOST Error: %s", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
if err = db.Save(e); err != nil {
l.Printf("MobileLocationPOST Error: %s", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
bytes, err := json.MarshalIndent(e, "", " ")
if err != nil {
l.Printf("MobileLocationPOST Error: while marshalling json %s", err)
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusCreated)
//.........這裏部分代碼省略.........