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

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

示例1: describeServicePorts

func describeServicePorts(spec kapi.ServiceSpec) string {
    switch len(spec.Ports) {
    case 0:
        return " no ports"

    case 1:
        port := portOrNodePort(spec, spec.Ports[0])
        if spec.Ports[0].TargetPort.String() == "0" || spec.ClusterIP == kapi.ClusterIPNone || port == spec.Ports[0].TargetPort.String() {
            return fmt.Sprintf(":%s", port)
        }
        return fmt.Sprintf(":%s -> %s", port, spec.Ports[0].TargetPort.String())

    default:
        pairs := []string{}
        for _, port := range spec.Ports {
            externalPort := portOrNodePort(spec, port)
            if port.TargetPort.String() == "0" || spec.ClusterIP == kapi.ClusterIPNone {
                pairs = append(pairs, externalPort)
                continue
            }
            if port.Port == int(port.TargetPort.IntVal) {
                pairs = append(pairs, port.TargetPort.String())
            } else {
                pairs = append(pairs, fmt.Sprintf("%s->%s", externalPort, port.TargetPort.String()))
            }
        }
        return " ports " + strings.Join(pairs, ", ")
    }
}

开发者ID:iconoeugen,项目名称:origin,代码行数:29,代码来源:projectstatus.go

示例2: Tr

// Tr translate content to target language.
func Tr(lang, format string, args ...interface{}) string {
    var section string
    parts := strings.SplitN(format, ".", 2)
    if len(parts) == 2 {
        section = parts[0]
        format = parts[1]
    }

    value, ok := locales.Get(lang, section, format)
    if ok {
        format = value
    }

    if len(args) > 0 {
        params := make([]interface{}, 0, len(args))
        for _, arg := range args {
            if arg != nil {
                val := reflect.ValueOf(arg)
                if val.Kind() == reflect.Slice {
                    for i := 0; i < val.Len(); i++ {
                        params = append(params, val.Index(i).Interface())
                    }
                } else {
                    params = append(params, arg)
                }
            }
        }
        return fmt.Sprintf(format, params...)
    }
    return fmt.Sprintf(format)
}

开发者ID:CodingDance,项目名称:harbor,代码行数:32,代码来源:i18n.go

示例3: RenderSpecialLink

func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte {
    ms := MentionPattern.FindAll(rawBytes, -1)
    for _, m := range ms {
        rawBytes = bytes.Replace(rawBytes, m,
            []byte(fmt.Sprintf(`<a href="/user/%s">%s</a>`, m[1:], m)), -1)
    }
    ms = commitPattern.FindAll(rawBytes, -1)
    for _, m := range ms {
        m = bytes.TrimSpace(m)
        i := strings.Index(string(m), "commit/")
        j := strings.Index(string(m), "#")
        if j == -1 {
            j = len(m)
        }
        rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf(
            ` <code><a href="%s">%s</a></code>`, m, ShortSha(string(m[i+7:j])))), -1)
    }
    ms = issueFullPattern.FindAll(rawBytes, -1)
    for _, m := range ms {
        m = bytes.TrimSpace(m)
        i := strings.Index(string(m), "issues/")
        j := strings.Index(string(m), "#")
        if j == -1 {
            j = len(m)
        }
        rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf(
            ` <a href="%s">#%s</a>`, m, ShortSha(string(m[i+7:j])))), -1)
    }
    ms = issueIndexPattern.FindAll(rawBytes, -1)
    for _, m := range ms {
        rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf(
            `<a href="%s/issues/%s">%s</a>`, urlPrefix, m[1:], m)), -1)
    }
    return rawBytes
}

开发者ID:Julianzz,项目名称:gogs,代码行数:35,代码来源:markdown.go

示例4: validateDefaultValueSchemaAgainstSchema

func (s *SpecValidator) validateDefaultValueSchemaAgainstSchema(path, in string, schema *spec.Schema) *Result {
    res := new(Result)
    if schema != nil {
        if schema.Default != nil {
            res.Merge(NewSchemaValidator(schema, s.spec.Spec(), path, s.KnownFormats).Validate(schema.Default))
        }
        if schema.Items != nil {
            if schema.Items.Schema != nil {
                res.Merge(s.validateDefaultValueSchemaAgainstSchema(path+".items", in, schema.Items.Schema))
            }
            for i, sch := range schema.Items.Schemas {
                res.Merge(s.validateDefaultValueSchemaAgainstSchema(fmt.Sprintf("%s.items[%d]", path, i), in, &sch))
            }
        }
        if schema.AdditionalItems != nil && schema.AdditionalItems.Schema != nil {
            res.Merge(s.validateDefaultValueSchemaAgainstSchema(fmt.Sprintf("%s.additionalItems", path), in, schema.AdditionalItems.Schema))
        }
        for propName, prop := range schema.Properties {
            res.Merge(s.validateDefaultValueSchemaAgainstSchema(path+"."+propName, in, &prop))
        }
        for propName, prop := range schema.PatternProperties {
            res.Merge(s.validateDefaultValueSchemaAgainstSchema(path+"."+propName, in, &prop))
        }
        if schema.AdditionalProperties != nil && schema.AdditionalProperties.Schema != nil {
            res.Merge(s.validateDefaultValueSchemaAgainstSchema(fmt.Sprintf("%s.additionalProperties", path), in, schema.AdditionalProperties.Schema))
        }
        for i, aoSch := range schema.AllOf {
            res.Merge(s.validateDefaultValueSchemaAgainstSchema(fmt.Sprintf("%s.allOf[%d]", path, i), in, &aoSch))
        }

    }
    return res
}

开发者ID:MStoykov,项目名称:go-swagger,代码行数:33,代码来源:spec.go

示例5: Run

// Run runs the the tunnel session
func (s *Session) Run() (err error) {
    defer s.recoverPanic("Session.Run")

    go func() {
        defer s.recoverPanic("Session.mux.Wait")
        code, err, debug1 := s.mux.Wait()
        //        s.Info("Session mux shutdown with code %v error %v debug %v", code, err, debug)
        log.Println(fmt.Sprintf("[INFO] Session mux shutdown with code %v error %v debug %v", code, err, debug1))
    }()

    defer s.mux.Close()

    // A tunnel session starts with an auth stream
    if err = s.handleAuth(); err != nil {
        return
    }

    // then we handle new streams sent from the client
    for {
        stream, err := s.mux.Accept()
        if err != nil {
            s.Shutdown()
            err := fmt.Errorf(fmt.Sprintf("Failed to accept stream: %v", err))
            log.Println(fmt.Sprintf("[ERROR] %v", err))
            return err
        }

        go s.handleStream(conn.Wrap(stream, "stream", s.id))
    }
}

开发者ID:shenshouer,项目名称:go-tunnel,代码行数:31,代码来源:session.go

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