Retour au cours

Introduction à net/http

Go (Golang) pour les microservices cloud-native

Le serveur Web intégré

Contrairement à beaucoup de langages, Go inclut un serveur HTTP prêt pour la production dans sa bibliothèque standard : net/http.

Le serveur le plus simple :

go package main

import ( "fmt" "net/http" )

func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { fmt.Fprint(w, "Hello World") })

http.ListenAndServe(":8080", nil)

}

C'est le cœur de chaque microservice Go.