-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Jian Zeng <[email protected]>
- Loading branch information
Showing
7 changed files
with
175 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package model | ||
|
||
import ( | ||
"gorm.io/gorm" | ||
) | ||
|
||
func AutoMigrate(db *gorm.DB) error { | ||
return db.AutoMigrate(&Repo{}, &RepoMeta{}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package model | ||
|
||
type StringMap map[string]string | ||
|
||
// Repo represents a Repository. | ||
type Repo struct { | ||
Name string `gorm:"primaryKey"` | ||
Interval string | ||
Image string | ||
StorageDir string | ||
User string | ||
BindIP string | ||
Network string | ||
LogRotCycle int | ||
Retry int | ||
Envs StringMap `gorm:"type:text;serializer:json"` | ||
Volumes StringMap `gorm:"type:text;serializer:json"` | ||
// sqlite3 does not have builtin datetime type | ||
CreatedAt int64 `gorm:"autoCreateTime"` | ||
UpdatedAt int64 `gorm:"autoUpdateTime"` | ||
} | ||
|
||
// RepoMeta represents the metadata of a Repository. | ||
type RepoMeta struct { | ||
Name string `gorm:"primaryKey"` | ||
Upstream string | ||
Size int64 | ||
ExitCode int | ||
CreatedAt int64 `gorm:"autoCreateTime"` | ||
UpdatedAt int64 `gorm:"autoUpdateTime"` | ||
LastSuccess int64 | ||
PrevRun int64 | ||
NextRun int64 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
func (s *Server) handlerListContainers(c echo.Context) error { | ||
// FIXME: implement this | ||
return nil | ||
} | ||
|
||
func (s *Server) handlerCreateContainer(c echo.Context) error { | ||
// FIXME: implement this | ||
return nil | ||
} | ||
|
||
func (s *Server) handlerRemoveContainer(c echo.Context) error { | ||
// FIXME: implement this | ||
return nil | ||
} | ||
func (s *Server) handlerGetContainerLogs(c echo.Context) error { | ||
// FIXME: implement this | ||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package server | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/labstack/echo/v4" | ||
"gorm.io/gorm" | ||
) | ||
|
||
func (s *Server) getDB(c echo.Context) *gorm.DB { | ||
return s.db.WithContext(c.Request().Context()) | ||
} | ||
|
||
func (s *Server) handlerListMetas(c echo.Context) error { | ||
ms := s.c.ListAllMetas() | ||
jobs := s.cron.Jobs() | ||
for i := 0; i < len(ms); i++ { | ||
job, ok := jobs[ms[i].Name] | ||
if ok { | ||
ms[i].NextRun = job.Next.Unix() | ||
} | ||
s.updateSyncStatus(&ms[i]) | ||
} | ||
return c.JSON(http.StatusOK, ms) | ||
} | ||
|
||
func (s *Server) handlerGetMeta(c echo.Context) error { | ||
name := c.Param("name") | ||
m, err := s.c.GetMeta(name) | ||
if err != nil { | ||
return notFound(err) | ||
} | ||
s.updateSyncStatus(m) | ||
jobs := s.cron.Jobs() | ||
job, ok := jobs[m.Name] | ||
if ok { | ||
m.NextRun = job.Next.Unix() | ||
} | ||
return c.JSON(http.StatusOK, m) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package server | ||
|
||
import ( | ||
"github.com/labstack/echo/v4" | ||
) | ||
|
||
func (s *Server) handlerListRepos(c echo.Context) error { | ||
// FIXME: implement this | ||
return nil | ||
} | ||
|
||
func (s *Server) handlerGetRepo(c echo.Context) error { | ||
// FIXME: implement this | ||
return nil | ||
} | ||
|
||
func (s *Server) handlerReloadAllRepos(c echo.Context) error { | ||
// FIXME: implement this | ||
return nil | ||
} | ||
|
||
func (s *Server) handlerReloadRepo(c echo.Context) error { | ||
// FIXME: implement this | ||
return nil | ||
} | ||
|
||
func (s *Server) handlerRemoveRepo(c echo.Context) error { | ||
// FIXME: implement this | ||
return nil | ||
} | ||
|
||
func (s *Server) handlerGetRepoLogs(c echo.Context) error { | ||
// FIXME: implement this | ||
return nil | ||
} |