December 2017
Intermediate to advanced
316 pages
6h 58m
English
Now, let us create a bare application server in Go with logging:
mkdir -p $GOPATH/src/github.com/narenaryan/basicServervi $GOPATH/src/github.com/narenaryan/basicServer/main.go
This file is a basic Go server to illustrate the proxy server's functioning. Then, we add a configuration to Nginx to proxy port 8000 (Go running port) to HTTP port (80). Now, let us write the code:
package mainimport ( "encoding/json" "fmt" "log" "net/http" "os" "time")// Book holds data of a booktype Book struct { ID int ISBN string Author string PublishedYear string}func main() { // File open for reading, writing and appending f, err := os.OpenFile("app.log", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666) if err != nil ...Read now
Unlock full access