Un piccolo esempio di come creare al volo un webserver in linguaggio Go.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
package main //Importo librerie Standard import "net/http" import "fmt" //Creo la funzione che mi stamperà la scritta sul browser func webserver(w http.ResponseWriter, r * http.Request){ fmt.Fprintf(w,"WebServer è On") } //Imposto il server in ascolto sulla porta 8080 in / func main(){ http.HandleFunc("/",webserver) http.ListenAndServe(":8080",nil) } |