mirror of
https://github.com/1f349/gomvn.git
synced 2024-12-21 23:44:07 +00:00
More changes
This commit is contained in:
parent
d103f6bcb7
commit
63aa76b63a
@ -61,7 +61,7 @@ func main() {
|
|||||||
|
|
||||||
srv := &http.Server{
|
srv := &http.Server{
|
||||||
Addr: config.Listen,
|
Addr: config.Listen,
|
||||||
Handler: routes.Router(db, config.Name, repoBasePath, config.Repository),
|
Handler: routes.Router(db, config.Name, repoDir, config.Repository),
|
||||||
ReadTimeout: time.Minute,
|
ReadTimeout: time.Minute,
|
||||||
ReadHeaderTimeout: time.Minute,
|
ReadHeaderTimeout: time.Minute,
|
||||||
WriteTimeout: time.Minute,
|
WriteTimeout: time.Minute,
|
||||||
|
7
database/extend-artifact.go
Normal file
7
database/extend-artifact.go
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
package database
|
||||||
|
|
||||||
|
import "strings"
|
||||||
|
|
||||||
|
func (a Artifact) GetPath() string {
|
||||||
|
return strings.Replace(a.MvnGroup, ".", "/", -1) + "/" + a.Artifact + "/" + a.Version
|
||||||
|
}
|
@ -1,3 +1,22 @@
|
|||||||
|
CREATE TABLE artifacts
|
||||||
|
(
|
||||||
|
mvn_group TEXT NOT NULL,
|
||||||
|
artifact TEXT NOT NULL,
|
||||||
|
version TEXT NOT NULL,
|
||||||
|
modified DATETIME NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE paths
|
||||||
|
(
|
||||||
|
user_id INTEGER UNIQUE,
|
||||||
|
path TEXT PRIMARY KEY,
|
||||||
|
deploy TINYINT,
|
||||||
|
created_at DATETIME,
|
||||||
|
updated_at DATETIME,
|
||||||
|
|
||||||
|
FOREIGN KEY (user_id) REFERENCES users (id)
|
||||||
|
);
|
||||||
|
|
||||||
CREATE TABLE users
|
CREATE TABLE users
|
||||||
(
|
(
|
||||||
id INTEGER UNIQUE PRIMARY KEY AUTOINCREMENT,
|
id INTEGER UNIQUE PRIMARY KEY AUTOINCREMENT,
|
||||||
|
@ -4,7 +4,25 @@
|
|||||||
|
|
||||||
package database
|
package database
|
||||||
|
|
||||||
import ()
|
import (
|
||||||
|
"database/sql"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Artifact struct {
|
||||||
|
MvnGroup string `json:"mvn_group"`
|
||||||
|
Artifact string `json:"artifact"`
|
||||||
|
Version string `json:"version"`
|
||||||
|
Modified time.Time `json:"modified"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type Path struct {
|
||||||
|
UserID sql.NullInt64 `json:"user_id"`
|
||||||
|
Path string `json:"path"`
|
||||||
|
Deploy sql.NullInt64 `json:"deploy"`
|
||||||
|
CreatedAt sql.NullTime `json:"created_at"`
|
||||||
|
UpdatedAt sql.NullTime `json:"updated_at"`
|
||||||
|
}
|
||||||
|
|
||||||
type User struct {
|
type User struct {
|
||||||
ID int64 `json:"id"`
|
ID int64 `json:"id"`
|
||||||
|
@ -1,10 +0,0 @@
|
|||||||
package types
|
|
||||||
|
|
||||||
import "time"
|
|
||||||
|
|
||||||
type Artifact struct {
|
|
||||||
MvnGroup string `json:"mvn_group"`
|
|
||||||
Artifact string `json:"artifact"`
|
|
||||||
Version string `json:"version"`
|
|
||||||
Modified time.Time `json:"modified"`
|
|
||||||
}
|
|
@ -1,30 +1,23 @@
|
|||||||
package paths
|
package paths
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/1f349/gomvn/database/types"
|
"github.com/1f349/gomvn/database"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
func GetRepositories(basePath string, repository []string) map[string][]*types.Artifact {
|
func GetRepositories(basePath string, repository []string) map[string][]*database.Artifact {
|
||||||
result := map[string][]*types.Artifact{}
|
result := map[string][]*database.Artifact{}
|
||||||
for _, repo := range repository {
|
for _, repo := range repository {
|
||||||
result[repo] = []*types.Artifact{}
|
result[repo] = []*database.Artifact{}
|
||||||
repoPath := filepath.Join(basePath, repo)
|
repoPath := filepath.Join(basePath, repo)
|
||||||
_ = filepath.Walk(repoPath, func(path string, info os.FileInfo, err error) error {
|
_ = filepath.Walk(repoPath, func(path string, info os.FileInfo, err error) error {
|
||||||
if strings.HasSuffix(path, ".pom") {
|
if strings.HasSuffix(path, ".pom") {
|
||||||
path = strings.Replace(path, "\\", "/", -1)
|
path = strings.Replace(path, "\\", "/", -1)
|
||||||
path = strings.Replace(path, repoPath+"/", "", 1)
|
path = strings.Replace(path, repoPath+"/", "", 1)
|
||||||
|
artifact := newArtifact(path, info.ModTime())
|
||||||
parts := strings.Split(path, "/")
|
|
||||||
last := len(parts) - 1
|
|
||||||
artifact := &types.Artifact{
|
|
||||||
MvnGroup: strings.Join(parts[0:last-2], "."),
|
|
||||||
Artifact: parts[last-2],
|
|
||||||
Version: parts[last-1],
|
|
||||||
Modified: info.ModTime(),
|
|
||||||
}
|
|
||||||
result[repo] = append(result[repo], artifact)
|
result[repo] = append(result[repo], artifact)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
@ -32,3 +25,14 @@ func GetRepositories(basePath string, repository []string) map[string][]*types.A
|
|||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func newArtifact(p string, mod time.Time) *database.Artifact {
|
||||||
|
parts := strings.Split(p, "/")
|
||||||
|
last := len(parts) - 1
|
||||||
|
return &database.Artifact{
|
||||||
|
MvnGroup: strings.Join(parts[0:last-2], "."),
|
||||||
|
Artifact: parts[last-2],
|
||||||
|
Version: parts[last-1],
|
||||||
|
Modified: mod,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -114,7 +114,3 @@ func (r *routeCtx) handlePut(rw http.ResponseWriter, req *http.Request, params h
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *routeCtx) handleGet(rw http.ResponseWriter, req *http.Request, params httprouter.Params) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user