10 examples of 'conversion go' in Go

Every line of 'conversion go' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Go code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
37func convert(n plan.Node) Flame {
38 var subFlames []Flame
39
40 for _, subOp := range n.Children {
41 subFlames = append(subFlames, convert(subOp))
42 }
43
44 return Flame{
45 Name: name(n),
46 Value: n.TotalTime,
47 Detail: detail(n),
48 Children: subFlames,
49 }
50}
59func (cd Iconv) Conv(b []byte, outbuf []byte) (out []byte, inleft int, err error) {
60
61 outn, inleft, err := cd.Do(b, len(b), outbuf)
62 if err == nil || err != E2BIG {
63 out = outbuf[:outn]
64 return
65 }
66
67 w := bytes.NewBuffer(nil)
68 w.Write(outbuf[:outn])
69
70 inleft, err = cd.DoWrite(w, b[len(b)-inleft:], inleft, outbuf)
71 if err != nil {
72 return
73 } else {
74 out = w.Bytes()
75 }
76 return
77}
31func AddConvert(f func(string) string) {
32 converts = append(converts, f)
33}
95func (h *CErrorHandler) ConvertGoInt(iError int) error {
96 return h.Convert(C.int(iError))
97}
5func TestConvert(t *testing.T) {
6 cases := []struct{ from, to, expected string }{
7 {"50mi", "km", "80.47km"},
8 {"50km", "mi", "31.07mi"},
9 }
10
11 for _, c := range cases {
12 str, err := Convert(c.from, c.to)
13 if err != nil {
14 t.Log("error should be nil", err)
15 t.Fail()
16 }
17 if str != c.expected {
18 t.Log("error should be "+c.expected+" but got", str)
19 t.Fail()
20 }
21 }
22
23}
28func convertAll(arg string) {
29 t, err := strconv.ParseFloat(arg, 64)
30 if err != nil {
31 fmt.Fprintf(os.Stderr, "cf: %v\n", err)
32 os.Exit(1)
33 }
34 f := tempconv.Fahrenheit(t)
35 c := tempconv.Celsius(t)
36 fmt.Printf("%s = %s, %s = %s\n",
37 f, tempconv.FToC(f), c, tempconv.CToF(c))
38}
411func TypeConvert(src string) string {
412 if val, ok := typeMap[src]; ok {
413 return val
414 }
415 return src
416}
202func convert(span *Span, arg Arg, to BasicType) (returns Return, effect Effect, err error) {
203 if x := arg.(*StructSymbol).LinkField("value", true); x != nil {
204 if basic, ok := x.(BasicSymbol); ok {
205 if converted, err := basic.ConvertTo(span, to); err != nil {
206 return nil, nil, err
207 } else {
208 return converted, nil, nil
209 }
210 } else {
211 return nil, nil, span.Errorf(nil, "non-basic type %v is not convertible to %v", x, to)
212 }
213 } else {
214 return nil, nil, span.Errorf(nil, "%v needs an argument", to)
215 }
216}
107func (c *CurrencyConverter) Convert(from, to string) (map[string]float64, error) {
108 result := make(map[string]float64)
109 v := url.Values{}
110 v.Set("q", from+"_"+to)
111 v.Set("compact", "ultra")
112
113 err := c.SendHTTPRequest(APIEndpointConvert, v, &result)
114 if err != nil {
115 return nil, err
116 }
117
118 return result, nil
119}
10func Convert(n int) string {
11 res := ""
12 if hasFactor(n, 3) {
13 res = "Pling"
14 }
15 if hasFactor(n, 5) {
16 res = fmt.Sprintf("%sPlang", res)
17 }
18 if hasFactor(n, 7) {
19 res = fmt.Sprintf("%sPlong", res)
20 }
21 if len(res) == 0 {
22 res = strconv.Itoa(n)
23 }
24
25 return res
26}

Related snippets