go:linkname

package main
import (
"fmt"
"example/ex"
)
func main() {
fmt.Println(ex.MyFunc())
}
package ex
import _ "unsafe"
//go:linkname myFuncWithBody example/ex.MyFunc
func
myFuncWithBody() string {
return "ok"
}
func MyFunc() string
touch test.s

go:norace

package main
var total int
func
add (){
total ++
}
func main() {
for i:=0;i<10;i++ {
go add()
}
}
package main
var total int
//go:norace
func
add (){
total ++
}
func main() {
for i:=0;i<10;i++ {
go add()
}
}

go:noinline

package main
func
hello() {
print("hello")
}
func main() {
hello()
}
go run -gcflags="-m" main.go
./main.go:4:6: can inline hello
./main.go:8:6: can inline main
./main.go:9:7: inlining call to hello
package main//go:noinline
func
hello() {
print("hello")
}
func main() {
hello()
}
./main.go:7:6: can inline main

go:noescape

//go:noescape
func test() *string // implemented in test.x assembly file.

Bonus: build tags

+build

// +build firstpackage main
import "fmt"
func init() {
fmt.Println("my first program")
}func main(){
fmt.Println("main function triggered")
}
// +build secondpackage main
import "fmt"
func init() {
fmt.Println("my second program")
}
go build -tags first && ./example
my first program
main function triggered
go build -tags second && ./example
my second program
// +build first second
// +build first
// +build first,second
// +build !first

Bonus: go generate tool

go:generate

package main
import (
"fmt"
)
//go:generate echo "my build process"
func
main() {
fmt.Println("hello world")
}
go generate main.go
my build process

--

--

--

Developer at Yemeksepeti

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

An Easy way to check the usage of Allocated Virtual Machine Quota in the subscription

Amazon EKS Deep Dive —Part 2 — Creating a cluster

Light Following Robot

The Art of Mobile Devops

OOPS (Object-Oriented Programming Language) Part-3

Journey into DevOps

The digital adoption problem in construction and how SymTerra makes a difference

[Challenges] LeetCode — Solve Regular Expression Matching using FA

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Burak Demirpolat

Burak Demirpolat

Developer at Yemeksepeti

More from Medium

Golang Interfaces

Simple IoT Messages Delivery With GoLang — 1

Securing gRPC connection with SSL/TLS Certificate using Go