在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:AaronO/go-git-http开源软件地址:https://github.com/AaronO/go-git-http开源编程语言:Go 99.3%开源软件介绍:go-git-httpA Smart Git Http server library in Go (golang) Examplepackage main
import (
"log"
"net/http"
"github.com/AaronO/go-git-http"
)
func main() {
// Get git handler to serve a directory of repos
git := githttp.New("/Users/aaron/git")
// Attach handler to http server
http.Handle("/", git)
// Start HTTP server
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
} Authentication examplepackage main
import (
"log"
"net/http"
"github.com/AaronO/go-git-http"
"github.com/AaronO/go-git-http/auth"
)
func main() {
// Get git handler to serve a directory of repos
git := githttp.New("/Users/aaron/git")
// Build an authentication middleware based on a function
authenticator := auth.Authenticator(func(info auth.AuthInfo) (bool, error) {
// Disallow Pushes (making git server pull only)
if info.Push {
return false, nil
}
// Typically this would be a database lookup
if info.Username == "admin" && info.Password == "password" {
return true, nil
}
return false, nil
})
// Attach handler to http server
// wrap authenticator around git handler
http.Handle("/", authenticator(git))
// Start HTTP server
err := http.ListenAndServe(":8080", nil)
if err != nil {
log.Fatal("ListenAndServe: ", err)
}
} |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论