This is inspired by A half-hour to learn Rust and Zig in 30 minutes.
Your first Go program as a classical "Hello World" is pretty simple:
First we create a workspace for our project:
| package main | |
| // Simple, single-threaded server using system calls instead of the net library. | |
| // | |
| // Omitted features from the go net package: | |
| // | |
| // - TLS | |
| // - Most error checking | |
| // - Only supports bodies that close, no persistent or chunked connections | |
| // - Redirects |
| package main | |
| import ( | |
| "fmt" | |
| "sort" | |
| "sync" | |
| "testing" | |
| "time" | |
| ) |
This is inspired by A half-hour to learn Rust and Zig in 30 minutes.
Your first Go program as a classical "Hello World" is pretty simple:
First we create a workspace for our project:
| package main | |
| import ( | |
| "os" | |
| "exec" | |
| ) | |
| func pipe_commands(commands ...*exec.Cmd) ([]byte, os.Error) { | |
| for i, command := range commands[:len(commands) - 1] { | |
| out, err := command.StdoutPipe() | |
| if err != nil { |
| package main | |
| import ( | |
| "bytes" | |
| "fmt" | |
| "io/ioutil" | |
| "log" | |
| "golang.org/x/crypto/ssh" | |
| kh "golang.org/x/crypto/ssh/knownhosts" |
| package main | |
| import ( | |
| "bufio" | |
| "io/ioutil" | |
| "os/signal" | |
| //"syscall" | |
| "fmt" | |
| "log" | |
| "os" |
| package main | |
| import ( | |
| "bufio" | |
| "io/ioutil" | |
| "os/signal" | |
| //"syscall" | |
| "fmt" | |
| "log" | |
| "os" |
| package main | |
| import ( | |
| "flag" | |
| "fmt" | |
| "log" | |
| "os" | |
| "runtime/pprof" | |
| "strconv" | |
| "sync" |
| package main | |
| /* | |
| #include <unistd.h> | |
| */ | |
| import "C" | |
| import ( | |
| "fmt" | |
| "time" | |
| ) |
| package main | |
| import ( | |
| "os" | |
| "os/exec" | |
| ) | |
| func Start(args ...string) (p *os.Process, err error) { | |
| if args[0], err = exec.LookPath(args[0]); err == nil { | |
| var procAttr os.ProcAttr |