diff options
author | 6543 <6543@obermui.de> | 2020-07-31 18:02:23 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-07-31 12:02:23 -0400 |
commit | b1cfb0d7a2cc65c42152b7ad8019819b6502dd36 (patch) | |
tree | 1ea45313f75aa33390b1804061b1b934bfbfe670 /vendor/github.com/google/go-github/v32/github/strings.go | |
parent | 48a423a8a8b00482b857d61e49d92de6acc81617 (diff) | |
download | gitea-b1cfb0d7a2cc65c42152b7ad8019819b6502dd36.tar.gz gitea-b1cfb0d7a2cc65c42152b7ad8019819b6502dd36.zip |
[Vendor] upgrade google/go-github to v32.1.0 (#12361) (#12390)
* upgrate go-github client to v32.1.0
* migrate
Diffstat (limited to 'vendor/github.com/google/go-github/v32/github/strings.go')
-rw-r--r-- | vendor/github.com/google/go-github/v32/github/strings.go | 93 |
1 files changed, 93 insertions, 0 deletions
diff --git a/vendor/github.com/google/go-github/v32/github/strings.go b/vendor/github.com/google/go-github/v32/github/strings.go new file mode 100644 index 0000000000..431e1cc6c1 --- /dev/null +++ b/vendor/github.com/google/go-github/v32/github/strings.go @@ -0,0 +1,93 @@ +// Copyright 2013 The go-github AUTHORS. All rights reserved. +// +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +package github + +import ( + "bytes" + "fmt" + "io" + + "reflect" +) + +var timestampType = reflect.TypeOf(Timestamp{}) + +// Stringify attempts to create a reasonable string representation of types in +// the GitHub library. It does things like resolve pointers to their values +// and omits struct fields with nil values. +func Stringify(message interface{}) string { + var buf bytes.Buffer + v := reflect.ValueOf(message) + stringifyValue(&buf, v) + return buf.String() +} + +// stringifyValue was heavily inspired by the goprotobuf library. + +func stringifyValue(w io.Writer, val reflect.Value) { + if val.Kind() == reflect.Ptr && val.IsNil() { + w.Write([]byte("<nil>")) + return + } + + v := reflect.Indirect(val) + + switch v.Kind() { + case reflect.String: + fmt.Fprintf(w, `"%s"`, v) + case reflect.Slice: + w.Write([]byte{'['}) + for i := 0; i < v.Len(); i++ { + if i > 0 { + w.Write([]byte{' '}) + } + + stringifyValue(w, v.Index(i)) + } + + w.Write([]byte{']'}) + return + case reflect.Struct: + if v.Type().Name() != "" { + w.Write([]byte(v.Type().String())) + } + + // special handling of Timestamp values + if v.Type() == timestampType { + fmt.Fprintf(w, "{%s}", v.Interface()) + return + } + + w.Write([]byte{'{'}) + + var sep bool + for i := 0; i < v.NumField(); i++ { + fv := v.Field(i) + if fv.Kind() == reflect.Ptr && fv.IsNil() { + continue + } + if fv.Kind() == reflect.Slice && fv.IsNil() { + continue + } + + if sep { + w.Write([]byte(", ")) + } else { + sep = true + } + + w.Write([]byte(v.Type().Field(i).Name)) + w.Write([]byte{':'}) + stringifyValue(w, fv) + } + + w.Write([]byte{'}'}) + default: + if v.CanInterface() { + fmt.Fprint(w, v.Interface()) + } + } +} |