FlashKeepers

Go · College · College and University

Go V: Standard Library and Web Services

net/http, encoding/json, io and bufio, time, flag, and building simple HTTP services in Go.

About this set

35 basic cards for College Go. It opens with "What does http.ListenAndServe() do?" and "What function in net/http registers a handler for a URL pattern?". Study it alongside the other College sets below.

35 cards · basic cards · AI-written, checked twice. Edit anything.

Study this set free Look inside first Get FlashKeepers for iPhone

Opens in your browser, no account. Get the iPhone and iPad app · Android app

What does http.ListenAndServe() do?
Show answerStarts an HTTP server listening on the specified address and port, blocking until the server exits
What function in net/http registers a handler for a URL pattern?
Show answerhttp.HandleFunc(pattern, handlerFunc)
What two methods must http.ResponseWriter implement?
Show answerWrite([]byte) and Header() http.Header
How do you extract query parameters from a *http.Request?
Show answerCall Request.URL.Query() to get a url.Values, then call Get() on it
What field on *http.Request contains the HTTP method?
Show answerThe Method field (e.g., "GET", "POST", "PUT")
What does http.Client.Do() return?
Show answerA *http.Response and an error
When should you use http.Client instead of http.Get()?
Show answerWhen you need to set custom headers, timeouts, or other request options
What is the http.Handler interface?
Show answerAn interface with one method: ServeHTTP(ResponseWriter, *Request)
What constant represents the HTTP status code 200 OK?
Show answerhttp.StatusOK
What does json.Marshal() return?
Show answerA byte slice containing JSON and an error
What must be the second argument to json.Unmarshal()?
Show answerA pointer to a value, usually a struct pointer
How do you specify a custom JSON key name for a struct field?
Show answerUse a struct tag: `json:"fieldName"`
When should you use json.Encoder instead of json.Marshal()?
Show answerWhen you are writing JSON to an io.Writer directly, like a file or HTTP response body
When should you use json.Decoder instead of json.Unmarshal()?
Show answerWhen you are reading JSON from an io.Reader, like a file or HTTP request body
What happens to unexported struct fields when marshaling to JSON?
Show answerThey are ignored and not included in the JSON output

20 more cards in the app

Study this set free