10 examples of 'golang type alias' in Go

Every line of 'golang type alias' 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
this disclaimer
541func resolveAliasAndPtrType(t *types.Type) *types.Type {
542 var prev *types.Type
543 for prev != t {
544 prev = t
545 if t.Kind == types.Alias {
546 t = t.Underlying
547 }
548 if t.Kind == types.Pointer {
549 t = t.Elem
550 }
551 }
552 return t
553}
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

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}
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}
420func getGoArray(typeName string) string {
421 return "[]" + typeName
422}
93func UnderlyingType(t Type) Type {
94 if t.Kind() == KIND_CUSTOM {
95 return t.(*CustomType).Decl.AliasedType
96 }
97 return t
98}
71func (pp *prettyPrinter) writeType(x interface{}) {
72 pp.writeIndent(TypeName(x))
73}
48func getArrayItemsType(t *Type, typ string) string {
49 if typ == "array" {
50 return fmt.Sprint(t.Items)
51 }
52 return strings.TrimSuffix(typ, "[]")
53}
1956func (b *float32Builder) GoType(typ interface{}) *float32Builder {
1957 b.desc.goType(typ, float32Type)
1958 return b
1959}
134func TypeToValue(t *sysl.Type) *sysl.Value {
135 m := MakeValueMap()
136 AddItemToValueMap(m, "docstring", MakeValueString(t.Docstring))
137 AddItemToValueMap(m, "attrs", attrsToValueMap(t.Attrs))
138 typeName, typeDetail := syslutil.GetTypeDetail(t)
139 AddItemToValueMap(m, "type", MakeValueString(typeName))
140 AddItemToValueMap(m, typeName, MakeValueString(typeDetail))
141 AddItemToValueMap(m, "optional", MakeValueBool(t.Opt))
142
143 switch x := t.Type.(type) {
144 case *sysl.Type_Tuple_:
145 AddItemToValueMap(m, "fields", fieldsToValueMap(x.Tuple.AttrDefs))
146 case *sysl.Type_Relation_:
147 AddItemToValueMap(m, "fields", fieldsToValueMap(x.Relation.AttrDefs))
148 case *sysl.Type_OneOf_:
149 unionSet := MakeValueSet()
150 for _, embeddedType := range x.OneOf.Type {
151 AppendItemToValueList(unionSet.GetSet(), MakeValueString(embeddedType.GetTypeRef().Ref.Path[0]))
152 }
153 AddItemToValueMap(m, "fields", unionSet)
154 case *sysl.Type_Sequence:
155 seqMap := MakeValueMap()
156 AddItemToValueMap(m, typeName, seqMap)
157 typeName, typeDetail = syslutil.GetTypeDetail(t.GetSequence())
158 AddItemToValueMap(seqMap, "type", MakeValueString(typeName))
159 AddItemToValueMap(seqMap, typeName, MakeValueString(typeDetail))
160 AddItemToValueMap(seqMap, "optional", MakeValueBool(false))
161 case *sysl.Type_Set:
162 setMap := MakeValueMap()
163 AddItemToValueMap(m, typeName, setMap)
164 typeName, typeDetail = syslutil.GetTypeDetail(t.GetSet())
165 AddItemToValueMap(setMap, "type", MakeValueString(typeName))
166 AddItemToValueMap(setMap, typeName, MakeValueString(typeDetail))
167 AddItemToValueMap(setMap, "optional", MakeValueBool(false))
168 }
169 return m
170}
145func isNullableType(t types.Type) bool {
146 return types.AssignableTo(types.Typ[types.UntypedNil].Underlying(), t) || t.String() == "string" // string is mapped to NSString*, which is nullable
147}

Related snippets