added basic http routing; fixed git integration
This commit is contained in:
@@ -8,19 +8,11 @@ import (
|
||||
|
||||
func main() {
|
||||
options := git.GitOptions{
|
||||
URL: "https://git.assilvestrar.club/lourenco/go-hugo-cms.git",
|
||||
}
|
||||
_, err := options.Clone()
|
||||
if err != nil {
|
||||
fmt.Errorf("%w", err)
|
||||
URL: "https://git.assilvestrar.club/lourenco/go-hugo-cms.git",
|
||||
Name: "go-hugo-cms",
|
||||
}
|
||||
|
||||
_, err = options.Open()
|
||||
if err != nil {
|
||||
fmt.Errorf("%w", err)
|
||||
}
|
||||
|
||||
err = options.Fetch()
|
||||
err := options.Fetch()
|
||||
if err != nil {
|
||||
fmt.Errorf("%w", err)
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package git
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
gogit "github.com/go-git/go-git/v5"
|
||||
@@ -12,25 +14,25 @@ type GitOptions struct {
|
||||
RecurseSubmodule bool
|
||||
}
|
||||
|
||||
func (g *GitOptions) Clone() (*gogit.Repository, error) {
|
||||
func (g *GitOptions) Clone() error {
|
||||
a := &gogit.CloneOptions{
|
||||
URL: g.URL,
|
||||
Progress: os.Stdout,
|
||||
}
|
||||
if err := a.Validate(); err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.Mkdir(g.Name, 0750); err != nil && !os.IsExist(err) {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
result, err := gogit.PlainClone(g.Name, false, a)
|
||||
_, err := gogit.PlainClone(g.Name, false, a)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
return err
|
||||
}
|
||||
|
||||
return result, nil
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *GitOptions) Open() (*gogit.Repository, error) {
|
||||
@@ -38,20 +40,24 @@ func (g *GitOptions) Open() (*gogit.Repository, error) {
|
||||
}
|
||||
|
||||
func (g *GitOptions) Fetch() error {
|
||||
a := &gogit.FetchOptions{
|
||||
RemoteName: g.Name,
|
||||
RemoteURL: g.URL,
|
||||
}
|
||||
if err := a.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
repo, err := g.Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := repo.Fetch(a); err != nil {
|
||||
a := &gogit.FetchOptions{
|
||||
RemoteName: "origin",
|
||||
Progress: os.Stdout,
|
||||
}
|
||||
if err := a.Validate(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err = repo.Fetch(a); err != nil {
|
||||
if err == gogit.NoErrAlreadyUpToDate { // not an actual error
|
||||
io.WriteString(os.Stdout, fmt.Sprintln("already up to date")) // keeping this here just for debug
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
|
||||
11
pkg/http/http.go
Normal file
11
pkg/http/http.go
Normal file
@@ -0,0 +1,11 @@
|
||||
package main
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
|
||||
func (c *ginContext) HttpHandler() {
|
||||
r := gin.Default()
|
||||
|
||||
r.GET("/list", g.listPosts())
|
||||
|
||||
r.Run()
|
||||
}
|
||||
Reference in New Issue
Block a user