本文整理汇总了Golang中github.com/davecgh/go-spew/spew.Dump函数的典型用法代码示例。如果您正苦于以下问题:Golang Dump函数的具体用法?Golang Dump怎么用?Golang Dump使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Dump函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestParseInfo
func TestParseInfo(t *testing.T) {
expectations := map[string]*TVNameParseResult{
"Sleepy.Hollow.S03E01.720p.HDTV.x264-AVS": {
Name: "Sleepy Hollow",
CleanedName: "Sleepy Hollow S03E01 720p HDTV x264-AVS",
Country: "",
Episode: "1",
Season: "3",
Airdate: "",
},
"NBC.Nightly.News.2016.02.17.WEB-DL.x264-2Maverick": {
Name: "NBC Nightly News",
CleanedName: "NBC Nightly News 2016 02 17 WEB-DL x264-2Maverick",
Country: "",
Episode: "02/17",
Season: "2016",
Airdate: "2016.02.17",
},
}
for name, v := range expectations {
res, err := ParseInfo(name)
if err != nil {
t.Fatalf("Error %v", err)
}
if !reflect.DeepEqual(v, res) {
t.Errorf("Diff in Parse output for %s", name)
fmt.Println("Expected:")
spew.Dump(v)
fmt.Println("Got:")
spew.Dump(res)
}
}
}
示例2: main
func main() {
fileSet := token.NewFileSet()
astFile, err := parser.ParseFile(fileSet, "minimal.go", nil, parser.ParseComments)
if err != nil {
panic(err)
}
ast.Print(fileSet, astFile)
return
astFile.Decls = append(astFile.Decls[:0], append([]ast.Decl{&ast.FuncDecl{
Name: ast.NewIdent("MyNewFunc"),
Type: &ast.FuncType{
Func: 15,
Params: &ast.FieldList{
Opening: 29,
Closing: 30,
},
},
}}, astFile.Decls[0:]...)...)
offset := astFile.Decls[0].End() - astFile.Decls[0].Pos()
intoffset := int(offset)
fmt.Println("offset", offset)
astFile.Comments[0].List[0].Slash += offset
// astFile.Comments[0].List[0].Slash = 18
astFile.Decls[1].(*ast.GenDecl).TokPos += offset
astFile.Decls[1].(*ast.GenDecl).Lparen += offset
astFile.Decls[1].(*ast.GenDecl).Rparen += offset
fileSetFile := fileSet.File(1)
newFileSet := token.NewFileSet()
newFileSetFile := newFileSet.AddFile("whatever", 1, fileSetFile.Size()+int(offset))
newFileSetFile.SetLines([]int{
0,
13,
14,
15,
15 + intoffset,
20 + intoffset,
21 + intoffset,
32 + intoffset,
33 + intoffset,
}) // hardcoded for now
fmt.Println("astFile:")
spew.Dump(astFile)
fmt.Println()
fmt.Println()
fmt.Println("fileSet:")
spew.Dump(fileSet)
buf := new(bytes.Buffer)
err = printer.Fprint(buf, newFileSet, astFile)
if err != nil {
panic(err)
}
fmt.Println(buf)
}
示例3: SetColor
func (c *ColorChannel) SetColor(state *channels.ColorState) error {
if state.Mode != "hue" {
return fmt.Errorf("TODO: Only color mode 'hue' is supported atm.")
}
spew.Dump("setting color", state)
hue := uint32(*state.Hue * float64(math.MaxUint8-1))
saturation := uint32(*state.Saturation * float64(math.MaxUint8-1))
request := &gateway.DevSetColorReq{
DstAddress: &gateway.GwAddressStructT{
AddressType: gateway.GwAddressTypeT_UNICAST.Enum(),
IeeeAddr: c.device.deviceInfo.IeeeAddress,
},
HueValue: &hue,
SaturationValue: &saturation,
}
spew.Dump(request)
response := &gateway.GwZigbeeGenericRspInd{}
err := c.device.driver.gatewayConn.SendAsyncCommand(request, response, 2*time.Second)
if err != nil {
return fmt.Errorf("Error setting color state : %s", err)
}
if response.Status.String() != "STATUS_SUCCESS" {
return fmt.Errorf("Failed to set color state. status: %s", response.Status.String())
}
return c.fetchState()
}
示例4: ReadBinlog
func ReadBinlog(reader io.Reader) (err error) {
c := &proto.BufReader{Reader: bufio.NewReader(reader)}
buf := &bytes.Buffer{}
r := &proto.BufReader{Reader: bufio.NewReader(buf)}
tmp := make([]byte, 4)
_, err = c.Read(tmp)
if err != nil {
return
}
// http://dev.mysql.com/doc/internals/en/binlog-file-header.html
if bytes.Compare(tmp, []byte{0xfe, 0x62, 0x69, 0x6e}) != 0 {
err = ErrFileHeader
return
}
h := &EventHeader{}
h.Read(c)
spew.Dump(h)
_, err = io.CopyN(buf, c, int64(h.EventSize))
if err != nil {
panic(err)
}
f := &FormatDescriptionEvent{}
f.Read(r)
spew.Dump(f)
return
}
示例5: main
func main() {
parser := yasha.ParserFromFile("/home/manveru/Dropbox/Public/d2rp_test_replays/813230338.dem")
parser.OnFileInfo = func(fileinfo *dota.CDemoFileInfo) { spew.Dump(fileinfo) }
parser.OnSayText2 = func(tick int, obj *dota.CUserMsg_SayText2) { spew.Dump(tick, obj) }
parser.OnChatEvent = func(tick int, obj *dota.CDOTAUserMsg_ChatEvent) { spew.Dump(tick, obj) }
parser.Parse()
}
示例6: TestPubKeys
func TestPubKeys(t *testing.T) {
for _, test := range pubKeyTests {
pk, err := btcec.ParsePubKey(test.key, btcec.S256())
if err != nil {
if test.isValid {
t.Errorf("%s pubkey failed when shouldn't %v",
test.name, err)
}
continue
}
if !test.isValid {
t.Errorf("%s counted as valid when it should fail",
test.name)
continue
}
var pkStr []byte
switch test.format {
case btcec.TstPubkeyUncompressed:
pkStr = (*btcec.PublicKey)(pk).SerializeUncompressed()
case btcec.TstPubkeyCompressed:
pkStr = (*btcec.PublicKey)(pk).SerializeCompressed()
case btcec.TstPubkeyHybrid:
pkStr = (*btcec.PublicKey)(pk).SerializeHybrid()
}
if !bytes.Equal(test.key, pkStr) {
t.Errorf("%s pubkey: serialized keys do not match.",
test.name)
spew.Dump(test.key)
spew.Dump(pkStr)
}
}
}
示例7: main
func main() {
a := []interface{}{1, 1.1, "abc", 2, 2.2, "def", 3, 3.3}
fmt.Println(sumOfArray(a))
fmt.Println(sumOfFloat(a))
fmt.Printf("\n--- omake ---\n\n")
masano := newHuman("masano")
dog := newAnimal("pochi")
monster := newMonster("godzilla")
var g greeter
g = masano
ret1, ok1 := g.(greeter) // greeter を実装しているかチェック。
spew.Dump(ret1, ok1)
g.greet()
fmt.Println()
g = dog
ret2, ok2 := g.(*animal) // animal 構造体かどうかチェック。メソッドレシーバが *animal なのでここは *animal になるっぽい。よくわからんが。
spew.Dump(ret2, ok2)
g.greet()
fmt.Println()
// インターフェースじゃなかったらキャストすればよい。
ret3, ok3 := interface{}(monster).(greeter) // greeter を実装しているかチェック。
ret4, ok4 := interface{}(monster.name).(string) // monster.name は string かチェック。
spew.Dump(ret3, ok3, ret4, ok4)
}
示例8: main
func main() {
var a Figure = newTriangle(10, 10) // Triangle 構造体はインタフェース Figure を実装しているので、Figure 型になれる。
fmt.Println(a.kindOf())
fmt.Println(a.area())
a.print()
// 以下の図形も同様。
var b Figure = newRectangle(10, 10)
fmt.Println(b.kindOf())
fmt.Println(b.area())
b.print()
c := newCircle(100) // この場合は何型なんだ?
fmt.Println(c.kindOf())
fmt.Println(c.area())
c.print()
fmt.Println()
spew.Dump(a, b, c) // 別に Figure 型になる、というわけではないのか。
fmt.Println()
var interfaced Figure
interfaced = newTriangle(1, 1)
spew.Dump(interfaced) // 明示的にインターフェース型の変数を用意してそれに代入しても、Triangle 型は Triangle 型のようだ。
fmt.Println()
// 各図形は Figure インターフェースを実装した Figure 型だぜ。
// これで sumOfArea() が使えるぜ。
var figures []Figure = []Figure{a, b, c}
// やったぜ。
fmt.Println(sumOfArea(figures))
}
示例9: SetTags
func (c *Client) SetTags(uid string, fields map[string]interface{}) error {
session := c.MgoSession.New()
defer session.Close()
store := session.DB(c.Cfg.Mongo.Db).C("Storage")
fields["version"] = 0
timestamp := int64(time.Now().Unix() / 1000)
change := mgo.Change{
Update: bson.M{
"$set": bson.M{"last_visit": timestamp},
"$inc": bson.M(fields),
},
ReturnNew: true,
Upsert: true,
}
resultUps := Storage{}
info, err := store.Find(bson.M{"uid": uid}).Apply(change, &resultUps)
if c.Debug {
fmt.Print("set tags info: ")
spew.Dump(info)
fmt.Print("resultUps: ")
spew.Dump(resultUps)
}
if err != nil {
panic(err)
}
return nil
}
示例10: TestWidth
func TestWidth(t *testing.T) {
s0 := "つのだ☆HIRO"
s1 := "11111111111"
spew.Dump(s0)
spew.Dump(s1)
// above not align for setting East Asian Ambiguous to wide!!
if strWidth(s0) != strWidth(s1) {
t.Error("str len failed")
}
len1 := []rune{'a', '2', '&', '「', 'オ', '。'} //will false: 'ᆵ', 'ᄚ', 'ᄒ'
for _, v := range len1 {
if charWidth(v) != 1 {
t.Error("len1 failed")
}
}
len2 := []rune{'漢', '字', '한', '자', '你', '好', 'だ', '。', '%', 's', 'E', 'ョ', '、', 'ヲ'}
for _, v := range len2 {
if charWidth(v) != 2 {
t.Error("len2 failed")
}
}
}
示例11: TestReplSetGetStatusResponseRewriterSuccess
func TestReplSetGetStatusResponseRewriterSuccess(t *testing.T) {
proxyMapper := fakeProxyMapper{
m: map[string]string{
"a": "1",
"b": "2",
"c": "3",
},
}
in := bson.M{
"members": []interface{}{
bson.M{
"name": "a",
"stateStr": "PRIMARY",
},
bson.M{
"name": "b",
},
bson.M{
"name": "c",
"stateStr": "ARBITER",
},
},
}
out := bson.M{
"members": []interface{}{
bson.M{
"name": "1",
"stateStr": "PRIMARY",
},
bson.M{
"name": "2",
},
bson.M{
"name": "3",
"stateStr": "ARBITER",
},
},
}
r := &ReplSetGetStatusResponseRewriter{
ProxyMapper: proxyMapper,
ReplyRW: &ReplyRW{},
}
var client bytes.Buffer
if err := r.Rewrite(&client, fakeSingleDocReply(in)); err != nil {
t.Fatal(err)
}
actualOut := bson.M{}
doc := client.Bytes()[headerLen+len(emptyPrefix):]
if err := bson.Unmarshal(doc, &actualOut); err != nil {
t.Fatal(err)
}
if !reflect.DeepEqual(out, actualOut) {
spew.Dump(out)
spew.Dump(actualOut)
t.Fatal("did not get expected output")
}
}
示例12: main
func main() {
a := "hello, world"
b := []byte{'h', 'y'}
// byte スライスは ASCII 文字しかダメってこと?
// でも file.go はちゃんとできてるぞ?
// c := []byte{'你', '你'}
// あー違う、文字列を []byte にするんだから、こうだ。
c := []byte("你好")
fmt.Printf("[%s]\n", a)
fmt.Printf("[%20s]\n", a)
fmt.Printf("[%-20s]\n", a)
fmt.Printf("[%q]\n", a)
fmt.Printf("[%20q]\n", a)
fmt.Printf("[%-20q]\n", a)
fmt.Printf("[%s]\n", b)
fmt.Printf("[%20s]\n", b)
fmt.Printf("[%-20s]\n", b)
fmt.Printf("[%q]\n", b)
fmt.Printf("[%20q]\n", b)
fmt.Printf("[%-20q]\n", b)
fmt.Printf("[%s]\n", c)
fmt.Printf("[%20s]\n", c)
fmt.Printf("[%-20s]\n", c)
fmt.Printf("[%q]\n", c)
fmt.Printf("[%20q]\n", c)
fmt.Printf("[%-20q]\n", c)
// "你好" はたぶん 1 文字 3 byte なんですかね。
fmt.Println()
fmt.Println("你好 な []byte をループで回す")
for _, v := range c {
spew.Dump(v)
}
// ふむふむ!
// 文字(列)は []byte (uint8: 0 - 255) である。
// 16 進数表記に直したらご覧の通りです!
fmt.Println()
fmt.Println("你を 16 進数で")
fmt.Printf("%x\n", "你")
fmt.Println("你の []byte を 16 進数で")
fmt.Printf("%x %x %x\n", c[0], c[1], c[2])
// で、rune ってのはコードポイント(Unicode 規格における、その文字の ID みたいなもん)を int32 な値で示している。
// コードポイントの文脈では、16 進数な rune 値がコードポイントになる。
// たとえば '你' は int32: 20320 で 16 進数だと 4f60 である。
// コードポイントはつまり、U+4f60 となる。
fmt.Println()
fmt.Println("你 の rune")
spew.Dump('你')
fmt.Println("你 の rune を 16 進数で")
fmt.Printf("%x\n", '你')
fmt.Println("你 の rune をコードポイントで")
fmt.Printf("%U\n", '你')
}
示例13: testScaled
// Test groups creation
func testScaled(t *testing.T) {
//Init
RemoveAllGroups()
RemoveAllPriceRules()
groupID := "ProductsToScale"
//createGroup
group := new(Group)
group.Type = ProductGroup
group.ID = groupID
group.Name = groupID
//create pricerule
priceRule := NewPriceRule(PriceRuleIDSale)
priceRule.Name = map[string]string{
"de": PriceRuleIDSale,
"fr": PriceRuleIDSale,
"it": PriceRuleIDSale,
}
priceRule.Type = TypePromotionOrder
priceRule.Description = priceRule.Name
priceRule.Action = ActionScaled
priceRule.ScaledAmounts = append(priceRule.ScaledAmounts, ScaledAmountLevel{FromValue: 100.0, ToValue: 150.0, Amount: 10, IsScaledAmountPercentage: true})
priceRule.ScaledAmounts = append(priceRule.ScaledAmounts, ScaledAmountLevel{FromValue: 150.01, ToValue: 100000.0, Amount: 50, IsScaledAmountPercentage: true})
priceRule.MaxUses = 10
priceRule.MaxUsesPerCustomer = 10
priceRule.WhichXYFree = XYCheapestFree
priceRule.IncludedProductGroupIDS = []string{groupID}
priceRule.IncludedCustomerGroupIDS = []string{}
//insert as well
group.AddGroupItemIDs([]string{ProductID1SKU1})
err := group.Upsert()
if err != nil {
log.Println(err)
}
//create order
orderVo, err := createMockOrderScaled(t)
if err != nil {
panic(err)
}
now := time.Now()
discountsVo, summary, err := ApplyDiscounts(orderVo, []string{""}, "", 0.05)
timeTrack(now, "Apply scaled voucher")
defer removeOrder(orderVo)
if err != nil {
panic(err)
}
fmt.Println("discounts for scaled percentage")
spew.Dump(discountsVo)
spew.Dump(*summary)
}
示例14: TestCanvasUnset
func TestCanvasUnset(t *testing.T) {
c := NewCanvas()
c.Set(0, 0)
c.Set(0, 1)
c.Set(0, 2)
c.Unset(0, 2)
spew.Dump(c)
c.Unset(0, 3)
spew.Dump(c)
}
示例15: main
func main() {
fmt.Println("Welcome to huexample")
brokerDetailsSlice, err := hue.DiscoverBridges()
if err != nil {
fmt.Println("Error while discovering bridges:", err)
return
}
if len(brokerDetailsSlice) == 0 {
fmt.Println("No bridge details found. Stopping.")
return
}
fmt.Printf("Found %d bridges:\n", len(brokerDetailsSlice))
spew.Dump(brokerDetailsSlice)
fmt.Printf("Continueing with first bridge found, id: %s\n", brokerDetailsSlice[0].ID)
fmt.Println("Going to create user with empty username, bridge will generate a username.")
bridge := hue.NewBridge(brokerDetailsSlice[0].InternalIPAddress)
newUsername, err := bridge.CreateNewUser("huexample", "")
if err != nil {
fmt.Printf("have error: %s\n", err)
return
}
fmt.Printf("Successfully created new user. Got username: %s\n", newUsername)
// update the Username field on Bridge instance with the user we just created
bridge.Username = newUsername
bridgeConfiguration, err := bridge.FetchConfiguration()
if err != nil {
fmt.Printf("have error: %s\n", err)
return
}
fmt.Printf("Bridge name is '%s'.\n", bridgeConfiguration.Name)
fmt.Printf("Bridge has %d users.\n", len(bridgeConfiguration.Whitelist))
lights, err := bridge.Lights()
if err != nil {
fmt.Printf("have error: %s\n", err)
return
}
fmt.Printf("Have %d lights.\n", len(lights))
spew.Dump(lights[0].Attributes())
// err = lights[0].SetName("Lange lamp")
// if err != nil {
// fmt.Printf("Have error: %s\n", err)
// }
}