mirror of
https://code.forgejo.org/actions/go-versions
synced 2025-06-08 11:38:22 +02:00
Implement builders to build Go from source code
This commit is contained in:
parent
8c06ab5f1e
commit
6cf25b0561
21 changed files with 836 additions and 0 deletions
27
tests/source/maps/maps.go
Normal file
27
tests/source/maps/maps.go
Normal file
|
@ -0,0 +1,27 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
|
||||
m := make(map[string]int)
|
||||
|
||||
m["k1"] = 7
|
||||
m["k2"] = 13
|
||||
|
||||
fmt.Println("map:", m)
|
||||
|
||||
v1 := m["k1"]
|
||||
fmt.Println("v1: ", v1)
|
||||
|
||||
fmt.Println("len:", len(m))
|
||||
|
||||
delete(m, "k2")
|
||||
fmt.Println("map:", m)
|
||||
|
||||
_, prs := m["k2"]
|
||||
fmt.Println("prs:", prs)
|
||||
|
||||
n := map[string]int{"foo": 1, "bar": 2}
|
||||
fmt.Println("map:", n)
|
||||
}
|
26
tests/source/methods/methods.go
Normal file
26
tests/source/methods/methods.go
Normal file
|
@ -0,0 +1,26 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type rect struct {
|
||||
width, height int
|
||||
}
|
||||
|
||||
func (r *rect) area() int {
|
||||
return r.width * r.height
|
||||
}
|
||||
|
||||
func (r rect) perim() int {
|
||||
return 2*r.width + 2*r.height
|
||||
}
|
||||
|
||||
func main() {
|
||||
r := rect{width: 10, height: 5}
|
||||
|
||||
fmt.Println("area: ", r.area())
|
||||
fmt.Println("perim:", r.perim())
|
||||
|
||||
rp := &r
|
||||
fmt.Println("area: ", rp.area())
|
||||
fmt.Println("perim:", rp.perim())
|
||||
}
|
7
tests/source/simple/simple.go
Normal file
7
tests/source/simple/simple.go
Normal file
|
@ -0,0 +1,7 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
func main() {
|
||||
fmt.Println("Hello, world.")
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue