refactor: added more implementation details
This commit is contained in:
parent
50e6b53091
commit
a1a9c6407f
6 changed files with 86 additions and 4 deletions
27
pkg/client/client.go
Normal file
27
pkg/client/client.go
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
package client
|
||||||
|
|
||||||
|
import "net/http"
|
||||||
|
|
||||||
|
type HTTPBody []byte
|
||||||
|
type HTTPHeader map[string]string
|
||||||
|
type HTTPEnvelope struct {
|
||||||
|
Path string
|
||||||
|
Method string
|
||||||
|
Header HTTPHeader
|
||||||
|
Body HTTPBody
|
||||||
|
CACert string
|
||||||
|
}
|
||||||
|
|
||||||
|
type Client struct {
|
||||||
|
BaseURI string
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(uri string) Client {
|
||||||
|
return Client{
|
||||||
|
BaseURI: uri,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Client) MakeRequest(env HTTPEnvelope) (*http.Response, []byte, error) {
|
||||||
|
http.DefaultTransport.(*http.Transport)
|
||||||
|
}
|
||||||
|
|
@ -1,14 +1,16 @@
|
||||||
package configurator
|
package configurator
|
||||||
|
|
||||||
type Plugin interface {
|
type Plugin interface {
|
||||||
// plugin data
|
|
||||||
Name() string
|
Name() string
|
||||||
Version() string
|
Version() string
|
||||||
Description() string
|
Description() string
|
||||||
Metadata() map[string]string
|
Metadata() map[string]string
|
||||||
|
|
||||||
// run the plugin
|
|
||||||
Init() error
|
Init() error
|
||||||
Run() error
|
Run() error
|
||||||
Cleanup() error
|
Cleanup() error
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func RunPlugin() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
|
||||||
19
pkg/plugins/jinja2.go
Normal file
19
pkg/plugins/jinja2.go
Normal file
|
|
@ -0,0 +1,19 @@
|
||||||
|
package plugin
|
||||||
|
|
||||||
|
type Jinja2 struct{}
|
||||||
|
|
||||||
|
func Name() string { return "jinja2" }
|
||||||
|
func Version() string { return "test" }
|
||||||
|
func Description() string { return "Renders Jinja 2 templates" }
|
||||||
|
func Metadata() map[string]string {
|
||||||
|
return map[string]string{
|
||||||
|
"author.name": "David J. Allen",
|
||||||
|
"author.email": "davidallendj@gmail.com",
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Init() {
|
||||||
|
// initialize Jinja2 (gonja)
|
||||||
|
}
|
||||||
|
func Run() {}
|
||||||
|
func Cleanup() {}
|
||||||
1
pkg/plugins/smd.go
Normal file
1
pkg/plugins/smd.go
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
package plugin
|
||||||
|
|
@ -4,10 +4,42 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"git.towk2.me/towk/configurator/pkg/util"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (s *Service) Download() http.HandlerFunc {
|
func (s *Service) Download() http.HandlerFunc {
|
||||||
return func(w http.ResponseWriter, r *http.Request) {
|
return func(w http.ResponseWriter, r *http.Request) {
|
||||||
|
var (
|
||||||
|
path = strings.TrimPrefix(r.URL.Path, "/download")
|
||||||
|
fileInfo os.FileInfo
|
||||||
|
out *os.File
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
|
||||||
|
fmt.Printf("download path: %v\n", path)
|
||||||
|
|
||||||
|
// determine if path is directory, file, or exists
|
||||||
|
if fileInfo, err = os.Stat(filepath.Clean(path)); err != nil {
|
||||||
|
if fileInfo.IsDir() {
|
||||||
|
// recursively walk dir acompressednd get all filenames
|
||||||
|
// download directory as archive
|
||||||
|
out, err = os.Create(fmt.Sprintf("%s.tar", path))
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
}
|
||||||
|
err = util.CreateArchive([]string{path}, out)
|
||||||
|
if err != nil {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
// download individual file
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ package service
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
|
@ -53,7 +54,7 @@ func (s *Service) Serve() error {
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// general
|
// general
|
||||||
router.Get("/download", s.Download())
|
router.Get("/download/*", s.Download())
|
||||||
router.Post("/upload", s.Upload())
|
router.Post("/upload", s.Upload())
|
||||||
router.Get("/list", s.List())
|
router.Get("/list", s.List())
|
||||||
|
|
||||||
|
|
@ -77,7 +78,7 @@ func (s *Service) Serve() error {
|
||||||
|
|
||||||
// always available public routes go here
|
// always available public routes go here
|
||||||
router.HandleFunc("/status", s.GetStatus)
|
router.HandleFunc("/status", s.GetStatus)
|
||||||
return nil
|
return http.ListenAndServe(":8080", router)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *Service) requireAuth() bool {
|
func (s *Service) requireAuth() bool {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue