10 examples of 'golang function type' in Go

Every line of 'golang function type' 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
226func GoNativeType(t design.DataType) string {
227 switch actual := t.(type) {
228 case design.Primitive:
229 switch actual.Kind() {
230 case design.BooleanKind:
231 return "bool"
232 case design.IntegerKind:
233 return "int"
234 case design.NumberKind:
235 return "float64"
236 case design.StringKind:
237 return "string"
238 case design.DateTimeKind:
239 return "time.Time"
240 case design.UUIDKind:
241 return "uuid.UUID"
242 case design.AnyKind:
243 return "interface{}"
244 default:
245 panic(fmt.Sprintf("goa bug: unknown primitive type %#v", actual))
246 }
247 case *design.Array:
248 return "[]" + GoNativeType(actual.ElemType.Type)
249 case design.Object:
250 return "map[string]interface{}"
251 case *design.Hash:
252 return fmt.Sprintf("map[%s]%s", GoNativeType(actual.KeyType.Type), GoNativeType(actual.ElemType.Type))
253 case *design.MediaTypeDefinition:
254 return GoNativeType(actual.Type)
255 case *design.UserTypeDefinition:
256 return GoNativeType(actual.Type)
257 default:
258 panic(fmt.Sprintf("goa bug: unknown type %#v", actual))
259 }
260}
68func (self *luaState) ToGoFunction(index int) GoFunction {
69 val := self.stack.get(index)
70 switch x := val.(type) {
71 case GoFunction:
72 return x
73 default:
74 return nil
75 }
76}
21func goType(t TypeInfo) reflect.Type {
22 switch t.Type() {
23 case TypeVarchar, TypeAscii, TypeInet:
24 return reflect.TypeOf(*new(string))
25 case TypeBigInt, TypeCounter:
26 return reflect.TypeOf(*new(int64))
27 case TypeTimestamp:
28 return reflect.TypeOf(*new(time.Time))
29 case TypeBlob:
30 return reflect.TypeOf(*new([]byte))
31 case TypeBoolean:
32 return reflect.TypeOf(*new(bool))
33 case TypeFloat:
34 return reflect.TypeOf(*new(float32))
35 case TypeDouble:
36 return reflect.TypeOf(*new(float64))
37 case TypeInt:
38 return reflect.TypeOf(*new(int))
39 case TypeDecimal:
40 return reflect.TypeOf(*new(*inf.Dec))
41 case TypeUUID, TypeTimeUUID:
42 return reflect.TypeOf(*new(UUID))
43 case TypeList, TypeSet:
44 return reflect.SliceOf(goType(t.(CollectionType).Elem))
45 case TypeMap:
46 return reflect.MapOf(goType(t.(CollectionType).Key), goType(t.(CollectionType).Elem))
47 case TypeVarint:
48 return reflect.TypeOf(*new(*big.Int))
49 case TypeTuple:
50 // what can we do here? all there is to do is to make a list of interface{}
51 tuple := t.(TupleTypeInfo)
52 return reflect.TypeOf(make([]interface{}, len(tuple.Elems)))
53 default:
54 return nil
55 }
56}
74func toTypescriptType(t reflect.Type) string {
75 switch t.Kind() {
76 case reflect.Bool:
77 return "boolean"
78 case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64, reflect.Uint,
79 reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64:
80 return "number"
81 case reflect.String:
82 return "string"
83 case reflect.Slice:
84 if t.Elem().Kind() == reflect.Uint8 {
85 // []byte is serialized as base64 encoded string
86 return "string /* base64 encoded */"
87 }
88 return "Array<" + toTypescriptType(t.Elem()) + ">"
89 case reflect.Ptr:
90 return toTypescriptType(t.Elem()) + " | undefined"
91 case reflect.Struct:
92 if t.PkgPath() == "time" && t.Name() == "Time" {
93 return "string"
94 }
95 if strings.HasSuffix(t.PkgPath(), "ashirt-server/backend/dtos") {
96 return t.Name()
97 }
98 panic(fmt.Errorf("Type from unknown package: %s, (%s)", t.PkgPath(), t.Name()))
99 }
100 panic(fmt.Errorf("Unknown kind: %s", t.Kind()))
101}
811func typeBuiltin() *Builtin {
812 return &Builtin{
813 Fn: func(line string, scope *Scope, args ...Object) Object {
814 if len(args) != 1 {
815 return NewError(line, ARGUMENTERROR, "1", len(args))
816 }
817 return NewString(fmt.Sprintf("%s", args[0].Type()))
818 },
819 }
820}
65func goNilRecast(dataType string) (interface{}, error) {
66 switch dataType {
67 case Integer:
68 return 0, nil
69
70 case Float, Number:
71 return float64(0), nil
72
73 case Boolean:
74 return false, nil
75
76 case CodeBlock, Json, JsonLines:
77 return "{}", nil
78
79 default:
80 return "", nil
81 }
82}
638func (s *swagger) isBuiltin(t types.Type) bool {
639 if types.IsBuiltin(t) {
640 return true
641 }
642 switch strings.TrimPrefix(t.String(), "*") {
643 case "uuid.UUID", "UUID", "json.RawMessage", "bson.ObjectId", "time.Time", "multipart.FileHeader":
644 return true
645 default:
646 return false
647 }
648}
292func make_func_type(rettype *Ctype, paramtypes []*Ctype, has_vaargs bool) *Ctype {
293 r := &Ctype{}
294 r.typ = CTYPE_FUNC
295 r.rettype = rettype
296 r.params = paramtypes
297 r.hasva = has_vaargs
298 return r
299}
70func (g *Generator) templFChoriaTypeToGo(v string) string {
71 switch v {
72 case "string", "list":
73 return "string"
74 case "integer":
75 return "int64"
76 case "number", "float":
77 return "float64"
78 case "boolean":
79 return "bool"
80 case "hash":
81 return "map[string]interface{}"
82 case "array":
83 return "[]interface{}"
84 default:
85 return "interface{}"
86 }
87}
1013func (op concatOp) Type() hm.Type {
1014 tt := constructor.MakeTensorType(op.d, hm.TypeVariable('a'))
1015 fnt := make([]hm.Type, op.children+1)
1016 for i := range fnt {
1017 fnt[i] = tt
1018 }
1019
1020 return hm.NewFnType(fnt...)
1021}

Related snippets