Source File
server.go
Belonging Package
golang.org/x/pkgsite/internal/proxy
package proxy
import (
)
func ( *Server) (, string, bool) {
:= fmt.Sprintf("/%s/@v/%s.info", , )
.mux.HandleFunc(, func( http.ResponseWriter, *http.Request) {
if && .Header.Get(disableFetchHeader) == "true" {
http.Error(, "not found: temporarily unavailable", http.StatusGone)
return
}
http.ServeContent(, , , time.Now(), defaultInfo())
})
}
func ( *Server) (, string) {
.mux.HandleFunc(, func( http.ResponseWriter, *http.Request) {
:= .modules[]
:= [len()-1].Version
http.ServeContent(, , , time.Now(), defaultInfo())
})
}
return fmt.Sprintf("module %s\n\ngo 1.12", )
}
:= .Files["go.mod"]
if == "" {
= (.ModulePath)
}
.mux.HandleFunc(fmt.Sprintf("/%s/@v/%s.mod", .ModulePath, .Version),
func( http.ResponseWriter, *http.Request) {
http.ServeContent(, , .ModulePath, time.Now(), strings.NewReader())
})
}
func ( *Server) ( *Module) {
.mux.HandleFunc(fmt.Sprintf("/%s/@v/%s.zip", .ModulePath, .Version),
func( http.ResponseWriter, *http.Request) {
.mu.Lock()
.zipRequests++
.mu.Unlock()
http.ServeContent(, , .ModulePath, time.Now(), bytes.NewReader(.zip))
})
}
func ( *Server) ( string) {
.mux.HandleFunc(fmt.Sprintf("/%s/@v/list", ), func( http.ResponseWriter, *http.Request) {
.mu.Lock()
defer .mu.Unlock()
var []string
if , := .modules[]; {
for , := range {
if !version.IsPseudo(.Version) {
= append(, .Version)
}
}
}
http.ServeContent(, , , time.Now(), strings.NewReader(strings.Join(, "\n")))
})
}
func ( *Server) ( string, func( http.ResponseWriter, *http.Request)) {
.mux.HandleFunc(, )
}
func ( *Server) ( *Module) {
.addModule(, false)
}
func ( *Server) ( *Module, bool) {
.mu.Lock()
defer .mu.Unlock()
= cleanModule()
if , := .modules[.ModulePath]; ! {
if {
.handleList(.ModulePath)
if .Version != "master" {
.handleLatest(.ModulePath, fmt.Sprintf("/%s/@v/master.info", .ModulePath))
}
if .Version != "main" {
.handleLatest(.ModulePath, fmt.Sprintf("/%s/@v/main.info", .ModulePath))
}
} else {
.mux.HandleFunc(fmt.Sprintf("/%s/@v/list", .ModulePath), func( http.ResponseWriter, *http.Request) {
http.ServeContent(, , .ModulePath, time.Now(), strings.NewReader(""))
})
.mux.HandleFunc(fmt.Sprintf("/%s/@latest", .ModulePath), func( http.ResponseWriter, *http.Request) {
http.Error(, "not found", http.StatusGone)
})
}
}
.handleInfo(.ModulePath, .Version, .NotCached)
.handleMod()
.handleZip()
.modules[.ModulePath] = append(.modules[.ModulePath], )
return semver.Compare(.modules[.ModulePath][].Version, .modules[.ModulePath][].Version) < 0
})
}
func ( *Server) () int {
.mu.Lock()
defer .mu.Unlock()
return .zipRequests
}
const versionTime = "2019-01-30T00:00:00Z"
func ( *Module) *Module {
if .Version == "" {
.Version = "v1.0.0"
}
:= map[string]string{}
for , := range .Files {
:= .ModulePath + "@" + .Version + "/" +
[] =
}
, := testhelper.ZipContents()
if != nil {
panic()
}
.zip =
return
}
func ( string) *strings.Reader {
return strings.NewReader(fmt.Sprintf("{\n\t\"Version\": %q,\n\t\"Time\": %q\n}", , versionTime))
![]() |
The pages are generated with Golds v0.3.2-preview. (GOOS=darwin GOARCH=amd64) Golds is a Go 101 project developed by Tapir Liu. PR and bug reports are welcome and can be submitted to the issue list. Please follow @Go100and1 (reachable from the left QR code) to get the latest news of Golds. |