Last active
December 3, 2019 18:08
-
-
Save dhcgn/be188d6809c773dc873a184e4ac06959 to your computer and use it in GitHub Desktop.
GoLang Demos
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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 | |
#> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
fmt.Println("hello world") | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$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