本文整理汇总了Golang中github.com/kr/pretty.Formatter函数的典型用法代码示例。如果您正苦于以下问题:Golang Formatter函数的具体用法?Golang Formatter怎么用?Golang Formatter使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Formatter函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: MustNewWinPdhCollector
func MustNewWinPdhCollector(name, prefix string, opts config.Config_win_pdh_collector) *win_pdh_collector {
c := &win_pdh_collector{
name: name,
enabled: true,
prefix: prefix,
interval: opts.Interval.MustDuration(time.Second),
config: opts,
hPdh: pdh.NewPdhCollector(),
map_queries: make(map[string]config.Config_win_pdh_query),
}
for _, q := range opts.Queries {
if q.Metric == "" {
logging.Errorf("Error Phd Collector metric is empty: %# v", pretty.Formatter(q))
continue
}
c.hPdh.AddEnglishCounter(q.Query)
if q.Tags == nil {
q.Tags = newcore.AddTags.Copy()
}
if opts.Query_to_tag == true || q.Query_to_tag == true {
q.Tags["query"] = q.Query
}
c.map_queries[q.Query] = q
}
logging.Tracef("MustNewWinPdhCollector:opts.Queries: %# v", pretty.Formatter(opts.Queries))
logging.Tracef("MustNuewWinPdhCollector c.map_queries: %# v", pretty.Formatter(c.map_queries))
return c
}
示例2: TestGetChart
func TestGetChart(t *testing.T) {
server, zillow := testFixtures(t, chartPath, func(values url.Values) {
assertOnlyParam(t, values, zpidParam, zpid)
assertOnlyParam(t, values, unitTypeParam, unitType)
assertOnlyParam(t, values, widthParam, strconv.Itoa(width))
assertOnlyParam(t, values, heightParam, strconv.Itoa(height))
})
defer server.Close()
request := ChartRequest{Zpid: zpid, UnitType: unitType, Width: width, Height: height}
result, err := zillow.GetChart(request)
if err != nil {
t.Fatal(err)
}
expected := &ChartResult{
XMLName: xml.Name{Space: "http://www.zillowstatic.com/vstatic/8d9b5f1/static/xsd/Chart.xsd", Local: "chart"},
Request: request,
Message: Message{
Text: "Request successfully processed",
Code: 0,
},
Url: "http://www.zillow.com/app?chartDuration=1year&chartType=partner&height=150&page=webservice%2FGetChart&service=chart&showPercent=true&width=300&zpid=48749425",
}
if !reflect.DeepEqual(result, expected) {
t.Fatalf("expected:\n %#v\n\n but got:\n %#v\n\n diff:\n %s\n",
pretty.Formatter(expected), pretty.Formatter(result), pretty.Diff(expected, result))
}
}
示例3: TestCopy_MakeTarStream_SingleFileToDir
func TestCopy_MakeTarStream_SingleFileToDir(t *testing.T) {
tmpDir := makeTmpDir(t, map[string]string{
"foo.txt": "hello",
})
defer os.RemoveAll(tmpDir)
assertions := [][3]string{
{"foo.txt", "foo", "foo"},
{"foo.txt", "foo/", "foo/foo.txt"},
}
for _, a := range assertions {
includes := []string{a[0]}
excludes := []string{}
dest := a[1]
t.Logf("includes: %# v", pretty.Formatter(includes))
t.Logf("excludes: %# v", pretty.Formatter(excludes))
t.Logf("dest: %# v", pretty.Formatter(dest))
stream, err := makeTarStream(tmpDir, dest, "COPY", includes, excludes, nil)
if err != nil {
t.Fatal(err)
}
out := writeReadTar(t, tmpDir, stream.tar)
assertion := strings.Join([]string{a[2]}, "\n") + "\n"
assert.Equal(t, assertion, out, "bad tar content for COPY %s %s", a[0], a[1])
}
}
示例4: main
func main() {
r := Rocket{
name: "Audrey Mark 0",
mass: Measurement{value: 0.05, units: "kg"},
area: Measurement{value: 0.0004, units: "m^2"},
drag: Measurement{value: 0.75, units: ""}, //seems reasonable
max_velocity: Measurement{value: 0, units: "m/s"},
max_altitude: Measurement{value: 0, units: "m"},
//https://en.wikipedia.org/wiki/Drag_coefficient
} //estimated rocket
e := Engine{
product_number: 1598,
name: "A8-3",
max_payload: Measurement{value: 0.085, units: "kg"},
delay: Measurement{value: 3, units: "s"},
impulse: Measurement{value: 2.5, units: "N-s"},
thrust: Measurement{value: 10.7, units: "N"},
mass: Measurement{value: 0.0162, units: "kg"},
propellant_mass: Measurement{value: 0.00312, units: "kg"},
burn_time: Measurement{value: 0.5, units: "s"},
} //example for A8-3
compute_terminal_conditons(&r, &e)
fmt.Printf("%# v\n", pretty.Formatter(r))
fmt.Printf("%# v\n", pretty.Formatter(e))
fmt.Printf("You're going to reach %v maximum velocity\n", r.max_velocity)
fmt.Println("Your maximum altitude will be:", r.max_altitude)
}
示例5: TestCopy_ListFiles_Dir_Simple
func TestCopy_ListFiles_Dir_Simple(t *testing.T) {
tmpDir := makeTmpDir(t, map[string]string{
"dir/foo.txt": "hello",
"dir/bar.txt": "hello",
})
defer os.RemoveAll(tmpDir)
includes := []string{
"dir",
}
excludes := []string{}
matches, err := listFiles(tmpDir, includes, excludes, "COPY", nil)
if err != nil {
t.Fatal(err)
}
t.Logf("includes: %# v", pretty.Formatter(includes))
t.Logf("excludes: %# v", pretty.Formatter(excludes))
t.Logf("matches: %# v", pretty.Formatter(matches))
assertions := [][2]string{
{tmpDir + "/dir/bar.txt", "dir/bar.txt"},
{tmpDir + "/dir/foo.txt", "dir/foo.txt"},
}
assert.Len(t, matches, len(assertions))
for i, a := range assertions {
assert.Equal(t, a[0], matches[i].src, "bad match src at index %d", i)
assert.Equal(t, a[1], matches[i].dest, "bad match dest at index %d", i)
}
}
示例6: TestCopy_MakeTarStream_SingleFileDirRename
func TestCopy_MakeTarStream_SingleFileDirRename(t *testing.T) {
tmpDir := makeTmpDir(t, map[string]string{
"c/foo.txt": "hello",
})
defer os.RemoveAll(tmpDir)
// ADD ./c /src --> /src
// ADD ./a/b[/1,2] /src -> /src[/1,2]
includes := []string{
"./c",
}
excludes := []string{}
dest := "/src"
t.Logf("includes: %# v", pretty.Formatter(includes))
t.Logf("excludes: %# v", pretty.Formatter(excludes))
t.Logf("dest: %# v", pretty.Formatter(dest))
stream, err := makeTarStream(tmpDir, dest, "COPY", includes, excludes, nil)
if err != nil {
t.Fatal(err)
}
out := writeReadTar(t, tmpDir, stream.tar)
assertion := strings.Join([]string{
"src/foo.txt",
}, "\n") + "\n"
assert.Equal(t, assertion, out, "bad tar content")
}
示例7: TestSNSMessageNotFound
func TestSNSMessageNotFound(t *testing.T) {
server := server.MockDBServer()
defer server.Close()
snsString := fmt.Sprintf(`{
"Type" : "Notification",
"MessageId" : "12",
"TopicArn" : "arn",
"Subject" : "Amazon S3 Notification",
"Message" : "{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"sc-gallery\"},\"object\":{\"key\":\"%v\",\"size\":71501}}}]}",
"Timestamp" : "2015-04-14T03:48:23.584Z",
"SignatureVersion" : "1",
"Signature" : "liP1M"
}`, "original_file/134444")
req := tests.MockRequest{}
req.Url = "/notify/sns/"
req.Method = "post"
req.Data = map[string]interface{}{}
utils.Decoder([]byte(snsString), &req.Data)
server.Test(&req, func(msg *tests.MockResponse) {
exception := "This message should be ignored."
if msg.Status != 200 {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error(exception)
}
if msg.Message != "" {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error(exception)
}
})
}
示例8: TestCreatePDFCollection
func TestCreatePDFCollection(t *testing.T) {
server := server.MockDBServer()
defer server.Close()
req := tests.MockRequest{}
req.Url = "/assets"
req.Method = "post"
req.Data = map[string]interface{}{
"mime_type": "application/pdf",
"name": randSeq(10),
"collection": randSeq(5),
}
server.Test(&req, func(msg *tests.MockResponse) {
utils.Convert(&msg.Data, &assetRet)
if msg.Status != 200 {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error("Asset creation should return status 200.")
}
for _, key := range []string{"upload_url", "url", "_id"} {
if val, ok := assetRet[key]; !ok || len(val) == 0 {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error(key + " should be a valid string in creation return.")
}
}
})
}
示例9: TestCopy_MakeTarStream_SubDirRenameWildcard
func TestCopy_MakeTarStream_SubDirRenameWildcard(t *testing.T) {
tmpDir := makeTmpDir(t, map[string]string{
"a/c/foo.txt": "hello",
"a/c/x/1.txt": "hello",
"a/c/x/2.txt": "hello",
})
defer os.RemoveAll(tmpDir)
includes := []string{
"a/*",
}
excludes := []string{}
dest := "/src"
t.Logf("includes: %# v", pretty.Formatter(includes))
t.Logf("excludes: %# v", pretty.Formatter(excludes))
t.Logf("dest: %# v", pretty.Formatter(dest))
stream, err := makeTarStream(tmpDir, dest, "COPY", includes, excludes)
if err != nil {
t.Fatal(err)
}
out := writeReadTar(t, tmpDir, stream.tar)
assertion := strings.Join([]string{
"src/c/foo.txt",
"src/c/x/1.txt",
"src/c/x/2.txt",
}, "\n") + "\n"
assert.Equal(t, assertion, out, "bad tar content")
}
示例10: TestSNSMessageIgnoredPath
func TestSNSMessageIgnoredPath(t *testing.T) {
server := server.MockDBServer()
defer server.Close()
snsString := fmt.Sprintf(`{
"Type" : "Notification",
"MessageId" : "12",
"TopicArn" : "arn",
"Subject" : "Amazon S3 Notification",
"Message" : "{\"Records\":[{\"s3\":{\"bucket\":{\"name\":\"sc-gallery\"},\"object\":{\"key\":\"%v\",\"size\":71501}}}]}",
"Timestamp" : "2015-04-14T03:48:23.584Z",
"SignatureVersion" : "1",
"Signature" : "liP1M"
}`, "/hello/world/")
req := tests.MockRequest{}
req.Url = "/notify/sns/"
req.Method = "post"
req.Data = map[string]interface{}{}
utils.Decoder([]byte(snsString), &req.Data)
server.Test(&req, func(msg *tests.MockResponse) {
exception := "This path should have been ignroed."
if msg.Status != 400 {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error(exception)
}
if !strings.Contains(msg.Message, "not meant to be monitored") {
fmt.Printf("%# v", pretty.Formatter(msg))
t.Error(exception)
}
})
}
示例11: TestCopy_ListFiles_Excludes_FileInAnyDir
func TestCopy_ListFiles_Excludes_FileInAnyDir(t *testing.T) {
tmpDir := makeTmpDir(t, map[string]string{
"a/test1.txt": "hello",
"b/test2.txt": "hello",
"c/d/e/test2.txt": "hello",
})
defer os.RemoveAll(tmpDir)
includes := []string{
".",
}
excludes := []string{
"**/test2.txt",
}
matches, err := listFiles(tmpDir, includes, excludes)
if err != nil {
t.Fatal(err)
}
t.Logf("includes: %# v", pretty.Formatter(includes))
t.Logf("excludes: %# v", pretty.Formatter(excludes))
t.Logf("matches: %# v", pretty.Formatter(matches))
assertions := [][2]string{
{tmpDir + "/a/test1.txt", "a/test1.txt"},
}
assert.Len(t, matches, len(assertions))
for i, a := range assertions {
assert.Equal(t, a[0], matches[i].src, "bad match src at index %d", i)
assert.Equal(t, a[1], matches[i].dest, "bad match dest at index %d", i)
}
}
示例12: ExampleProxy
// ExampleProxy shows a chain of servers and clients.
func ExampleProxy() {
log.Println("\n***** ExampleProxy *****\n")
// Real
var realServer = offers.MustNewServer(configure("Real Server"), offers.Offers{Configuration: configure("Server")}, ":4030") // Use s as the service.
go func() {
if err := realServer.Start(); err != nil {
panic(err)
}
}()
var realClient = offers.MustNewClient(configure("Real Client"), ":4030")
// Proxy
var proxyServer = offers.MustNewServer(configure("Proxy Server"), realClient, ":4031") // Use realClient as the service.
go func() {
if err := proxyServer.Start(); err != nil {
panic(err)
}
}()
var proxyClient = offers.MustNewClient(configure("Proxy Client"), ":4031").ForContext(offers.Context{ID: tigertonic.RandomBase62String(8)}).(offers.Client)
// Use
m, err := proxyClient.New(offer.Offer{Name: "nerddomo"})
if err != nil {
panic(err)
}
log.Printf("New: Got: %# v\n\n", pretty.Formatter(simplify(m)))
m, err = proxyClient.Get(m.ID)
if err != nil {
panic(err)
}
log.Printf("Get: Got: %# v\n\n", pretty.Formatter(simplify(m)))
m.Name = "test"
m, err = proxyClient.Set(m)
if err != nil {
panic(err)
}
log.Printf("Set: Got: %# v\n\n", pretty.Formatter(simplify(m)))
m, err = proxyClient.Delete(m)
if err != nil {
panic(err)
}
log.Printf("Delete: Got: %# v\n\n", pretty.Formatter(simplify(m)))
// Proxy
if err := proxyClient.Close(); err != nil {
panic(err)
}
if err := proxyServer.Stop(); err != nil {
panic(err)
}
// Real
if err := realClient.Close(); err != nil {
panic(err)
}
if err := realServer.Stop(); err != nil {
panic(err)
}
}
示例13: TestGetRateSummary
func TestGetRateSummary(t *testing.T) {
server, zillow := testFixtures(t, rateSummaryPath, func(values url.Values) {
assertOnlyParam(t, values, stateParam, state)
})
defer server.Close()
request := RateSummaryRequest{State: state}
result, err := zillow.GetRateSummary(request)
if err != nil {
t.Fatal(err)
}
expected := &RateSummary{
XMLName: xml.Name{Space: "http://www.zillow.com/static/xsd/RateSummary.xsd", Local: "rateSummary"},
Message: Message{
Text: "Request successfully processed",
Code: 0,
},
Today: []Rate{
Rate{LoanType: "thirtyYearFixed", Count: 1252, Value: 5.91},
Rate{LoanType: "fifteenYearFixed", Count: 839, Value: 5.68},
Rate{LoanType: "fiveOneARM", Count: 685, Value: 5.49},
},
LastWeek: []Rate{
Rate{LoanType: "thirtyYearFixed", Count: 8933, Value: 6.02},
Rate{LoanType: "fifteenYearFixed", Count: 5801, Value: 5.94},
Rate{LoanType: "fiveOneARM", Count: 3148, Value: 5.71},
},
}
if !reflect.DeepEqual(result, expected) {
t.Fatalf("expected:\n %#v\n\n but got:\n %#v\n\n diff:\n %s\n",
pretty.Formatter(expected), pretty.Formatter(result), pretty.Diff(expected, result))
}
}
示例14: TestCopy_MakeTarStream_WierdWildcards
func TestCopy_MakeTarStream_WierdWildcards(t *testing.T) {
tmpDir := makeTmpDir(t, map[string]string{
"abc.txt": "hello",
"adf.txt": "hello",
"bvz.txt": "hello",
})
defer os.RemoveAll(tmpDir)
includes := []string{
"a*.txt",
}
excludes := []string{}
dest := "./"
t.Logf("includes: %# v", pretty.Formatter(includes))
t.Logf("excludes: %# v", pretty.Formatter(excludes))
t.Logf("dest: %# v", pretty.Formatter(dest))
stream, err := makeTarStream(tmpDir, dest, "COPY", includes, excludes, nil)
if err != nil {
t.Fatal(err)
}
out := writeReadTar(t, tmpDir, stream.tar)
assertion := strings.Join([]string{
"./abc.txt",
"./adf.txt",
}, "\n") + "\n"
assert.Equal(t, assertion, out, "bad tar content")
}
示例15: main
func main() {
var (
mongoSession *mgo.Session
database *mgo.Database
collection *mgo.Collection
changeInfo *mgo.ChangeInfo
err error
)
if mongoSession, err = mgo.Dial("localhost"); err != nil {
panic(err)
}
database = mongoSession.DB("mgo_examples_03")
collection = database.C("todos")
// START OMIT
var todo = Todo{
Id: bson.NewObjectId(),
Task: "Demo mgo",
Created: time.Now(),
}
// This is a shortcut to collection.Upsert(bson.M{"_id": todo.id}, &todo)
if changeInfo, err = collection.UpsertId(todo.Id, &todo); err != nil {
panic(err)
}
// END OMIT
fmt.Printf("Todo: %# v", pretty.Formatter(todo))
fmt.Printf("Change Info: %# v", pretty.Formatter(changeInfo))
}