go-analyzer/tests/test_types.txt

57 lines
1.2 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

package main;
import (
"fmt";
"your_project/models";
)
type mile uint;
type BinaryOp func(int, int) int;
type text []string;
type empty struct{
};
type person struct{
name string;
age int;
};
type person2 struct{
name,second_name string;
age int;
person;
};
func main() {
var p models.Person;
var a,b,c,d models.Person;
var a,b,c models.Person = models.Person{name:"Tom", age:24}, models.Person{"Tom", 24}, models.Person{"Tom", 24};
var p models.Person = person{};
p1 := models.Person{"Tom", 24};
a, undefined := 1, person {};
var alice person = person{age: 23, name: "Alice"};
var tom = person {name: "Tom", age: 24};
var tom1 Person = Person{Name: "Tom", Age: 24};
tom2 := Person{Name: "Tom", Age: 24};
// Явное указание типа с пакетом
var tom3 models.Person = models.Person{Name: "Tom", Age: 24};
// Краткая форма
tom4 := models.Person{Name: "Tom", Age: 24};
// Вывод типа
var tom5 = models.Person{Name: "Tom", Age: 24};
fmt.Println(tom.name); // Tom
fmt.Println(tom.age); // 24
tom.age = 38; // изменяем значение
fmt.Println(tom.name, tom.age); // Tom 38
}