本文整理汇总了Golang中fmt.Sprint函数的典型用法代码示例。如果您正苦于以下问题:Golang Sprint函数的具体用法?Golang Sprint怎么用?Golang Sprint使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。

在下文中一共展示了Sprint函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: PrintMapRecursive

//  PrintMap prints a map - recursing through submaps
// concrete types, like map[float64]map[int]float64
//      would have to be converted element by element
//   to map[interface{}]interface{}
// the json.indent function might be similar
// but I did not bring it to work
func PrintMapRecursive(m1 map[interface{}]interface{}, depth int) string {
    b1 := new(bytes.Buffer)
    fiveSpaces := "       " // html spaces
    cxIndent := fmt.Sprint(depth * 40)
    depthStyle := ""
    if depth == 0 {
        depthStyle = "margin-top:8px; border-top: 1px solid #aaa;"
    } else {
        darkening := 16 - 2*depth
        bgc := fmt.Sprintf("%x%x%x", darkening, darkening, darkening)
        depthStyle = "margin:0;padding:0;background-color:#" + bgc + ";"
    }
    for k1, m2 := range m1 {
        b1.WriteString("<div style='" + depthStyle + "margin-left:" + cxIndent + "px;'>\n")
        b1.WriteString(fmt.Sprint(k1))
        //b1.WriteString( "<br>\n" )
        switch typedvar := m2.(type) {
        default:
            type_unknown := fmt.Sprintf("<br>\n &nbsp; &nbsp;  --this type switch does not support type %#v", typedvar)
            //panic(type_unknown)
            b1.WriteString(fiveSpaces + fmt.Sprintf("%#v", typedvar) + type_unknown)
        case string:
            b1.WriteString(fiveSpaces + typedvar)
        case int, float64:
            b1.WriteString(fiveSpaces + fmt.Sprint(typedvar))
        case nil:
            b1.WriteString("nil interface")
        case map[interface{}]interface{}:
            b1.WriteString(PrintMapRecursive(typedvar, depth+1))
        }
        b1.WriteString("<br>\n")
        b1.WriteString("</div>\n")
    }
    return b1.String()
}

开发者ID:aarzilli,项目名称:tools,代码行数:41,代码来源:print+map+recursive.go

示例2: Panic

func (entry *Entry) Panic(args ...interface{}) {
    if entry.Logger.Level >= Panic {
        msg := entry.log("panic", Panic, fmt.Sprint(args...))
        panic(msg)
    }
    panic(fmt.Sprint(args...))
}

开发者ID:rayleyva,项目名称:logrus,代码行数:7,代码来源:entry.go

示例3: DescribeCdnDomainBaseDetail

// DescribeCdnDomainBaseDetail version 2014-11-11
//
// required parameters:
//  name: DomainName, type: string
//
// optional parameters:
//  name: OwnerId, type: int64
//  name: ResourceOwnerAccount, type: string
//  name: ResourceOwnerId, type: int64
//  name: _method, type: string, optional values: GET|POST
//  name: _region, type: string
//  name: _scheme, type: string, optional values: http|https
func (api API) DescribeCdnDomainBaseDetail(DomainName string, optional openapi.M) (*DescribeCdnDomainBaseDetailResponse, error) {
    args := NewParams()

    args.Query.Set("Action", "DescribeCdnDomainBaseDetail")
    args.Query.Set("DomainName", DomainName)
    if v, ok := optional["OwnerId"]; ok {
        if OwnerId, ok := v.(int64); ok {
            args.Query.Set("OwnerId", fmt.Sprint(OwnerId))
        } else {
            return nil, errors.New("OwnerId must be int64")
        }
    }
    if v, ok := optional["ResourceOwnerAccount"]; ok {
        if ResourceOwnerAccount, ok := v.(string); ok {
            args.Query.Set("ResourceOwnerAccount", ResourceOwnerAccount)
        } else {
            return nil, errors.New("ResourceOwnerAccount must be string")
        }
    }
    if v, ok := optional["ResourceOwnerId"]; ok {
        if ResourceOwnerId, ok := v.(int64); ok {
            args.Query.Set("ResourceOwnerId", fmt.Sprint(ResourceOwnerId))
        } else {
            return nil, errors.New("ResourceOwnerId must be int64")
        }
    }
    if v, ok := optional["_method"]; ok {
        if s, ok := v.(string); ok {
            if !openapi.IsIn(s, "GET|POST") {
                return nil, errors.New("_method must be GET|POST")
            }
            args.Method = s
        } else {
            return nil, errors.New("_method must be string")
        }
    }
    if v, ok := optional["_region"]; ok {
        if s, ok := v.(string); ok {
            args.Region = s
        } else {
            return nil, errors.New("_region must be string")
        }
    }
    if v, ok := optional["_scheme"]; ok {
        if s, ok := v.(string); ok {
            if !openapi.IsIn(s, "http|https") {
                return nil, errors.New("_scheme must be http|https")
            }
            args.Scheme = s
        } else {
            return nil, errors.New("_scheme must be string")
        }
    }

    result := new(DescribeCdnDomainBaseDetailResponse)
    if err := api.Service.Do(result, args); err != nil {
        return nil, err
    }
    return result, nil
}

开发者ID:cn27001,项目名称:aliyun-openapi-go-sdk,代码行数:72,代码来源:apis.go

示例4: parseGauges

func parseGauges(info string) map[string]int64 {
    gauges_with_values := map[string]int64{
        "blocked_clients":           0,
        "connected_clients":         0,
        "instantaneous_ops_per_sec": 0,
        "latest_fork_usec":          0,
        "mem_fragmentation_ratio":   0,
        "migrate_cached_sockets":    0,
        "pubsub_channels":           0,
        "pubsub_patterns":           0,
        "uptime_in_seconds":         0,
        "used_memory":               0,
        "used_memory_lua":           0,
        "used_memory_peak":          0,
        "used_memory_rss":           0,
    }
    color.White("-------------------")
    color.White("GAUGES:")
    for gauge, _ := range gauges_with_values {
        r, _ := regexp.Compile(fmt.Sprint(gauge, ":([0-9]*)"))
        matches := r.FindStringSubmatch(info)
        if matches == nil {
            color.Yellow(fmt.Sprint("WARN: ", gauge, "is not displayed in redis info"))
        } else {
            value := matches[len(matches)-1]
            color.Cyan(fmt.Sprint(gauge, ": ", value))
            v, _ := strconv.ParseInt(value, 10, 64)
            gauges_with_values[gauge] = v
        }
    }
    return gauges_with_values
}

开发者ID:feelobot,项目名称:stadis,代码行数:32,代码来源:stadis.go

示例5: TestStatic

func TestStatic(t *testing.T) {
    var (
        instances = []string{"foo", "bar", "baz"}
        endpoints = map[string]endpoint.Endpoint{
            "foo": func(context.Context, interface{}) (interface{}, error) { return struct{}{}, nil },
            "bar": func(context.Context, interface{}) (interface{}, error) { return struct{}{}, nil },
            "baz": func(context.Context, interface{}) (interface{}, error) { return struct{}{}, nil },
        }
        factory = func(instance string) (endpoint.Endpoint, error) {
            if e, ok := endpoints[instance]; ok {
                return e, nil
            }
            return nil, fmt.Errorf("%s: not found", instance)
        }
    )
    p := static.NewPublisher(instances, factory, log.NewNopLogger())
    have, err := p.Endpoints()
    if err != nil {
        t.Fatal(err)
    }
    want := []endpoint.Endpoint{endpoints["foo"], endpoints["bar"], endpoints["baz"]}
    if fmt.Sprint(want) != fmt.Sprint(have) {
        t.Fatalf("want %v, have %v", want, have)
    }
}

开发者ID:sasha-s,项目名称:kit,代码行数:25,代码来源:publisher_test.go

最后编辑: kuteng  文档更新时间: 2021-08-23 19:14   作者:kuteng