Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
GoLang Demos
$code = @"
package main
import (
"fmt"
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}
func main() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
}
"@
Set-Content -Value $code -Path C:\Temp\webservice.go
$env:GOOS = 'windows'; $env:GOARCH = 'amd64'; go build -o C:\Temp\webservice_demo.exe C:\Temp\webservice.go
$env:GOOS = 'linux'; $env:GOARCH = 'amd64'; go build -o C:\Temp\webservice_demo_linux C:\Temp\webservice.go
$env:GOOS = 'linux'; $env:GOARCH = 'arm64'; go build -o C:\Temp\webservice_demo_arm C:\Temp\webservice.go
$env:GOOS = 'darwin'; $env:GOARCH = 'amd64'; go build -o C:\Temp\webservice_demo_mac C:\Temp\webservice.go
Get-ChildItem -Path C:\Temp\webservice_demo*
<#
Directory: C:\Temp
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 03.12.2019 17:54 7130624 webservice_demo.exe
-a---- 03.12.2019 17:54 7049592 webservice_demo_arm
-a---- 03.12.2019 17:54 7394885 webservice_demo_linux
-a---- 03.12.2019 17:54 7436184 webservice_demo_mac
#>
package main
import "fmt"
func main() {
fmt.Println("hello world")
}
package main
import (
"fmt"
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}
func main() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
}
$code = @"
package main
import (
"fmt"
"log"
"net/http"
)
func handler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintf(w, "Hi there, I love %s!", r.URL.Path[1:])
}
func main() {
http.HandleFunc("/", handler)
log.Fatal(http.ListenAndServe(":8080", nil))
}
"@
Set-Content -Value $code -Path C:\Temp\webservice.go
Start-Process "http://localhost:8080/Go"
go run C:\Temp\webservice.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.