本文整理汇总了Golang中github.com/k0kubun/pp.Println函数的典型用法代码示例。如果您正苦于以下问题:Golang Println函数的具体用法?Golang Println怎么用?Golang Println使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Println函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: sendInquiry
func sendInquiry(c web.C, w http.ResponseWriter, r *http.Request) {
formData := make(map[string][]string)
if err := r.ParseForm(); err != nil {
panic("parse error")
} else {
formData = r.PostForm
}
pp.Println(formData)
session, _ := store.Get(r, "inqury")
session.Values["message"] = "send inquery"
buf := new(bytes.Buffer)
gob.Register(map[string][]string{})
enc := gob.NewEncoder(buf)
if err := enc.Encode(&formData); err != nil {
pp.Println(err)
}
session.Values["formData"] = formData
if err := session.Save(r, w); err != nil {
pp.Println(err)
}
http.Redirect(w, r, "/", http.StatusFound)
}
示例2: SaveCustomer
// 顧客情報を保存します。
func SaveCustomer(customer *Customer) (*Customer, error) {
db, err := common.GetDB()
if err != nil {
panic(err.Error())
}
defer db.Close()
pp.Println(customer)
var existCustomer Customer
db.Where("ID = ?", customer.ID).First(&existCustomer)
pp.Println(existCustomer)
if existCustomer.ID != "" {
// 更新
customer.UpdatedAt = time.Now()
db.Model(&customer).Where("ID = ?", customer.ID).Update(customer)
} else {
// 新規登録
customer.ID = uuid.NewV4().String()
customer.CreatedAt = time.Now()
db.Create(&customer)
}
return customer, err
}
示例3: inquiry
func inquiry(c web.C, w http.ResponseWriter, r *http.Request) {
if tpl, err := pongo2.DefaultSet.FromFile("inquiry.tpl"); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
} else {
session, _ := store.Get(r, "inqury")
message := ""
msg := session.Values["message"]
_, ok := msg.(string)
if ok {
message = msg.(string)
session.Values["message"] = nil
session.Save(r, w)
}
bytes, err := tpl.ExecuteBytes(pongo2.Context{"title": "inquiry", "message": message})
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
formData := session.Values["formData"]
if formData != nil {
pp.Println(formData)
bytes = fillinform.Fill(bytes, formData.(map[string][]string), nil)
session.Values["formData"] = nil
if err := session.Save(r, w); err != nil {
pp.Println(err)
}
}
w.Write(bytes)
}
}
示例4: Say
func (c ChatServerClientSlack) Say(ch string, msg string) {
pp.Println(ch, msg)
title := "alert"
// 引用でおくるとき
_, err := json.Marshal(&payload{Attachments: []*attachment{
&attachment{
Fallback: title,
Pretext: title,
Fields: []*field{
&field{
Title: "",
Value: msg,
Short: false,
},
},
},
},
})
// フラットなテキスト + channel override
p, err := json.Marshal(&textPayload{Text: msg, Channel: ch})
res, err := http.PostForm(c.WebHookURL, url.Values{"payload": []string{string(p)}})
if err != nil {
log.Println("error on slack")
}
if res.StatusCode != 200 {
pp.Println(res.Status)
}
}
示例5: PayPalPaymentExecute
func PayPalPaymentExecute(ctx context.Context, w http.ResponseWriter, r *http.Request) {
pp.Println(r.Header)
pp.Println(r.Cookies())
buf := bytes.NewBufferString(fmt.Sprintf("{ \"payer_id\" : \"%s\"}", r.FormValue("PayerID")))
req, err := http.NewRequest("POST", fmt.Sprintf("https://api.sandbox.paypal.com/v1/payments/payment/%s/execute/", r.FormValue("paymentId")), buf)
if err != nil {
log.Fatalln(err)
renderer.JSON(w, 400, err.Error())
return
}
req.Header.Add("Content-Type", "application/json")
req.Header.Add("Authorization", fmt.Println("Bearer %s", authToken))
res, err := http.DefaultClient.Do(req)
if err != nil {
log.Fatalln(err)
renderer.JSON(w, 400, err.Error())
return
}
defer res.Body.Close()
data, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatalln(err)
renderer.JSON(w, 400, err.Error())
return
}
fmt.Println(string(data))
http.Redirect(w, r, "/payment/done", 302)
}
示例6: main
func main() {
cfg := NewConfig()
if err := cfg.Load("config.json"); err != nil {
log.Printf("[ERROR] %+v", err)
return
}
defer func() {
if err := cfg.Save(); err != nil {
log.Printf("[ERROR] %+v", err)
return
}
}()
if len(cfg.Ips) > 100 {
for k, v := range cfg.Ips {
cfg.DeleteIp(k)
log.Printf("Delete IP %s: %s", k, v)
break
}
}
fake.SetLang("ru")
ipParams := cfg.SetIp(fake.IPv4(), true)
ipParams.Description = fake.FullName()
ipParams.SetExpire(time.Now().Add(time.Minute))
pp.Println(cfg.AllowIp("181.113.250.128"))
pp.Println(cfg.AllowIp("89.155.206.159"))
}
示例7: apiCall
func apiCall(method string, params url.Values, callback func([]byte)) error {
params.Set("token", SLACK_TOKEN)
u := SLACK_API_URL + method
res, err := http.PostForm(u, params)
pp.Println(res.Request)
pp.Println(res.Header)
if err != nil {
if data, err := createErrorResponse(res.StatusCode); err != nil {
return err
} else {
callback(data)
}
}
pp.Println(res.StatusCode)
if res.StatusCode == http.StatusOK {
if resData, err := ioutil.ReadAll(res.Body); err != nil {
return err
} else {
callback(resData)
}
} else {
if data, err := createErrorResponse(res.StatusCode); err != nil {
return err
} else {
callback(data)
}
}
return nil
}
示例8: Loop
func (conn *Connection) Loop() {
for {
ws, err := conn.newWSConnection()
if err != nil {
log.Fatal(err)
}
defer ws.Close()
ws.SetDeadline(time.Now().Add(10 * time.Minute))
func() {
for {
data := json.RawMessage{}
if err := websocket.JSON.Receive(ws, &data); err != nil {
log.Printf("failed websocket json receive: %v", err)
return
}
event := &Type{}
if err := json.Unmarshal(data, event); err != nil {
log.Printf("failed json unmarshal: %v", err)
continue
}
v, ok := eventMapping[event.Type]
if !ok {
continue
}
typeOf := reflect.TypeOf(v)
ep := reflect.New(typeOf).Interface()
if err := json.Unmarshal(data, ep); err != nil {
log.Printf("failed json unmarshal for type: %v", err)
continue
}
switch e := ep.(type) {
case *HelloEvent:
// ...
case *MessageEvent:
conn.CallCb(*e)
case *ChannelCreatedEvent:
conn.channelMap[e.Channel.Id] = e.Channel.Name
pp.Println(conn.channelMap)
case *ChannelDeletedEvent:
delete(conn.channelMap, e.Channel)
pp.Println(conn.channelMap)
case *ChannelRenameEvent:
conn.channelMap[e.Channel.Id] = e.Channel.Name
pp.Println(conn.channelMap)
case *UserChangeEvent:
conn.userMap[e.User.Id] = e.User.Name
pp.Println(conn.userMap)
default:
}
}
}()
}
}
示例9: PaymentDone
func PaymentDone(ctx context.Context, w http.ResponseWriter, r *http.Request) {
r.ParseForm()
pp.Println(r.Form)
pp.Println(r.Header)
pp.Println(r.Cookies())
w.Write([]byte("OK"))
}
示例10: TestQueryMemoryCache
func TestQueryMemoryCache(t *testing.T) {
s := New()
defer s.Close()
q := s.QueryMemoryCache(testQuery, testArgs...)
pp.Println(q)
q = s.QueryMemoryCache(testQuery, testArgs...)
pp.Println(q)
}
示例11: TestQueryKVSCache
func TestQueryKVSCache(t *testing.T) {
s := New()
defer s.Close()
cacheKey := fmt.Sprintf("%s:%v", testQuery, testArgs)
s.KVS.Del(cacheKey)
q := s.QueryKVSCache(testQuery, testArgs...)
pp.Println(q)
q = s.QueryKVSCache(testQuery, testArgs...)
pp.Println(q)
}
示例12: main
func main() {
fmt.Println("Hello world!")
err := getError()
err = errors.Wrap(err, "open failed")
err = subErr(err)
err = errors.Wrap(err, "read config failed")
pp.Println("Cause: ", errors.Cause(err))
err = errors.Wrap(err, "New message")
pp.Println("Error: ", err)
fmt.Printf("[%+v]\n", err)
fmt.Printf("{%+v}\n", errors.Cause(err))
fmt.Printf("[%v]\n", err)
}
示例13: DebugDump
func DebugDump(v ...interface{}) {
if IsDebugging() {
for _, r := range v {
pp.Println(r)
}
}
}
示例14: itemHandler
func itemHandler(feed *rss.Feed, ch *rss.Channel, newitems []*rss.Item) {
fmt.Println("itemHandler")
fmt.Println(len(newitems), "new item(s) in", ch.Title, "of", feed.Url)
for _, item := range newitems {
pp.Println(item)
}
}
示例15: main
func main() {
// Init loggers
scenariolib.InitLogger(ioutil.Discard, os.Stdout, os.Stdout, os.Stderr)
// Seed Random based on current time
source := rand.NewSource(int64(time.Now().Unix()))
random := rand.New(source)
searchToken := os.Getenv("SEARCHTOKEN")
analyticsToken := os.Getenv("UATOKEN")
if searchToken == "" || analyticsToken == "" {
scenariolib.Error.Println("SEARCHTOKEN, UATOKEN need to be defined as env variables")
}
scenarioURL := os.Getenv("SCENARIOSURL")
if scenarioURL == "" {
scenariolib.Error.Println("SCENARIOSURL env variable needs to define a file path")
}
local := os.Getenv("LOCAL") == "true"
if local {
scenariolib.Info.Println("STARTING IN LOCAL MODE, MAKE SURE THE SCENARIOSURL IS A LOCAL PATH")
}
bot := scenariolib.NewUabot(local, scenarioURL, searchToken, analyticsToken, random)
quit := make(chan bool)
err := bot.Run(quit)
if err != nil {
scenariolib.Error.Println(err)
}
pp.Println("LOG >>> DONE")
}