Pourquoi ai-je besoin pour utiliser le protocole http.StripPrefix d'accéder à mes fichiers statiques?

principal.aller

package main

import (
    "net/http"
)

func main() {
    http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
    http.ListenAndServe(":8080", nil)
}

Structure de répertoire:

%GOPATH%/src/project_name/main.go
%GOPATH%/src/project_name/static/..files and folders ..

Même après la lecture de la documentation, j'ai du mal à comprendre ce qu'est exactement http.StripPrefix fait ici.

1) Pourquoi ne puis-je pas accéder à localhost:8080/static si je supprime http.StripPrefix?

2) Quelle URL cartes à /static dossier si je supprime cette fonction?

  • Avez-vous essayé http.La poignée("/static/', ' http.Serveur de fichiers(http.Dir("/")))?
  • http.Handle("/static/", http.FileServer(http.Dir(""))) œuvres.
InformationsquelleAutor Dante | 2015-01-14