When using net/http
, handling errors is kinda annoying.
http.HandleFunc("/foo", func(w http.ResponseWriter, r *http.Request) {
thing, err := storage.Get("thing")
if err != nil {
http.Error(w, err.Error(), 500)
package main | |
import ( | |
"bufio" | |
"fmt" | |
"io" | |
"log" | |
"os/exec" | |
) |
package httpx | |
import ( | |
"net/http" | |
) | |
func WithStatus(code int, handler http.Handler) http.Handler { | |
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { | |
w.WriteHeader(code) | |
handler.ServeHTTP(w, r) |
package main | |
import ( | |
"fmt" | |
"net/http" | |
"net/http/cgi" | |
"os" | |
) | |
type Handler func(http.ResponseWriter, *http.Request) |
package main | |
import ( | |
"fmt" | |
) | |
func main() { | |
for i := 0; i < 360; i++ { | |
fmt.Println(DegreeDifference(0, i)) | |
} |
<?xml version="1.0" encoding="UTF-8"?> | |
<!DOCTYPE Category SYSTEM "asterix.dtd"> | |
<!-- | |
Asterix Category 048 v1.14 definition | |
Author: dmarkus | |
Created: 13.2.2009. | |
Modified: 3.11.2013 : added items I048/55, I048/065 and I048/SP (FPS117-specific) |
package server | |
import "time" | |
type Service struct{} | |
type ConsumerType int | |
const ( | |
SingleConsumer ConsumerType = iota |
// Simple Arithmetics Grammar | |
// ========================== | |
// | |
// Accepts expressions like "2 * (3 + 4)" and computes their value. | |
Filter | |
= "//" path:Path { return path } | |
Expression | |
= Path |
package main | |
import ( | |
"encoding/xml" | |
"fmt" | |
"log" | |
) | |
func main() { | |
msg := &Message{ |
package main | |
import ( | |
"encoding/binary" | |
"fmt" | |
"log" | |
"time" | |
) | |
// Layout: [8 bytes: unix timestamp][4 bytes: sequence id] |