Envisioning a Go-Powered Ecosystem: The Ultimate Go Computer
20 Jun 2024
Manfred Touron
VP Eng., Gno.land
Manfred Touron
VP Eng., Gno.land
package main
import "fmt"
func main() {
fmt.Println("Hello, GopherCon EU! It's Manfred.")
}
2
Imagine a machine where Go is the only paradigm for all levels of computing:
Disclaimer: These slides present a mental exercise of what such a computer could look like. This is not a critique of current practices, but an exploration of using Go everywhere.
4func SomeHandler(w http.ResponseWriter, r *http.Request) { data := MyStruct{Field: "value"} // go logic _, err := json.NewEncoder(w).Encode(data) }
func SomeHandler() MyStruct { data := MyStruct{Field: "value"} return data }
func main() { flag.StringVar(&myStringFlag, "stringFlag", "default", "usage") flag.IntVar(&myIntFlag, "intFlag", 0, "usage") flag.Parse() MyFunc(*myStringFlag, *myIntFlag) } $> myprogram --stringFlag foo --intFlag 42
$> mypackage.MyFunc("stringValue", 42)
// Current approach // Compile and run the binary from the CLI // $ go build -o myapp // $ ./myapp package main func main() { mypackage.MyFunc() }
// Unified approach import "my/package" mypackage.MyFunc()
import "database/sql" db, err := sql.Open("driver", "source") _, err := db.Exec("CREATE TABLE IF NOT EXISTS users ...") _, err := db.Exec("INSERT INTO users ...") rows, err := db.Query("SELECT fields FROM users ...") defer rows.Close() for rows.Next() { /* logic */} err := rows.Err()
type User struct { Name string Age int } var users []User users = append(users, User{"John Doe", 30}) for _, user := range users { /* logic */ }
func main() { // logic } func init() { // logic }
func Foo() { // logic } $> myprogram.Foo() // resumes, executes, pauses
11Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away. -- Antoine de Saint-Exupéry