Update query parameter and make HTTPS by default (#4)

Resolves #2
Resolves #3

Co-authored-by: jolheiser <john.olheiser@gmail.com>
Reviewed-on: https://gitea.com/jolheiser/git-import/pulls/4
Co-authored-by: John Olheiser <john.olheiser@gmail.com>
Co-committed-by: John Olheiser <john.olheiser@gmail.com>
pull/5/head v0.3.0
John Olheiser 2021-02-22 04:22:34 +08:00
parent 9222b99fd1
commit 3c1a19d31c
1 changed files with 18 additions and 9 deletions

27
main.go
View File

@ -15,13 +15,14 @@ import (
var ( var (
Version = "develop" Version = "develop"
output string output string
author string author string
email string email string
gpg string gpg string
display bool display bool
ssh bool ssh bool
debug bool insecure bool
debug bool
) )
func main() { func main() {
@ -66,13 +67,17 @@ func main() {
Usage: "GPG key to sign with", Usage: "GPG key to sign with",
Destination: &gpg, Destination: &gpg,
}, },
&cli.BoolFlag{
Name: "insecure",
Usage: "Use HTTP instead of HTTPS by default",
Destination: &insecure,
},
&cli.BoolFlag{ &cli.BoolFlag{
Name: "debug", Name: "debug",
Usage: "Enable debug logging", Usage: "Enable debug logging",
Destination: &debug, Destination: &debug,
}, },
} }
app.UseShortOptionHandling = true
app.Action = doImport app.Action = doImport
if err := app.Run(os.Args); err != nil { if err := app.Run(os.Args); err != nil {
@ -95,8 +100,12 @@ func doImport(ctx *cli.Context) error {
return err return err
} }
if u.Scheme == "" { if u.Scheme == "" {
u.Scheme = "http" u.Scheme = "https"
if insecure {
u.Scheme = "http"
}
} }
u.RawQuery = "git-import=1"
beaver.Debugf("Getting git-import from %s", u.String()) beaver.Debugf("Getting git-import from %s", u.String())
res, err := http.Get(u.String()) res, err := http.Get(u.String())