Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
1e66a221e0 | |||
df318682fa |
2
.github/workflows/nfctl.yml
vendored
2
.github/workflows/nfctl.yml
vendored
@ -5,7 +5,7 @@ on:
|
|||||||
- 'release/nfctl/*'
|
- 'release/nfctl/*'
|
||||||
|
|
||||||
env:
|
env:
|
||||||
RELEASE_VERSION: v24.07.14-r3
|
RELEASE_VERSION: v24.09.23-r1
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build-job:
|
build-job:
|
||||||
|
16
ctx.go
16
ctx.go
@ -8,6 +8,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"github.com/google/uuid"
|
"github.com/google/uuid"
|
||||||
"github.com/loveuer/nf/internal/sse"
|
"github.com/loveuer/nf/internal/sse"
|
||||||
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"mime/multipart"
|
"mime/multipart"
|
||||||
"net"
|
"net"
|
||||||
@ -362,6 +363,21 @@ func (c *Ctx) HTML(html string) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *Ctx) RenderHTML(name, html string, obj any) error {
|
||||||
|
c.SetHeader("Content-Type", "text/html")
|
||||||
|
t, err := template.New(name).Parse(html)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return t.Execute(c.Writer, obj)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Ctx) Redirect(url string, code int) error {
|
||||||
|
http.Redirect(c.Writer, c.Request, url, code)
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
func (c *Ctx) Write(data []byte) (int, error) {
|
func (c *Ctx) Write(data []byte) (int, error) {
|
||||||
return c.Writer.Write(data)
|
return c.Writer.Write(data)
|
||||||
}
|
}
|
||||||
|
@ -3,15 +3,16 @@ package cmd
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/url"
|
||||||
|
"os"
|
||||||
|
"path"
|
||||||
|
|
||||||
"github.com/loveuer/nf/nft/log"
|
"github.com/loveuer/nf/nft/log"
|
||||||
"github.com/loveuer/nf/nft/nfctl/clone"
|
"github.com/loveuer/nf/nft/nfctl/clone"
|
||||||
"github.com/loveuer/nf/nft/nfctl/opt"
|
"github.com/loveuer/nf/nft/nfctl/opt"
|
||||||
"github.com/loveuer/nf/nft/nfctl/tp"
|
"github.com/loveuer/nf/nft/nfctl/tp"
|
||||||
"github.com/loveuer/nf/nft/nfctl/version"
|
"github.com/loveuer/nf/nft/nfctl/version"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"net/url"
|
|
||||||
"os"
|
|
||||||
"path"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -44,6 +45,7 @@ func initNew() {
|
|||||||
err error
|
err error
|
||||||
urlIns *url.URL
|
urlIns *url.URL
|
||||||
pwd string
|
pwd string
|
||||||
|
moduleName string
|
||||||
projectDir string
|
projectDir string
|
||||||
initBs []byte
|
initBs []byte
|
||||||
renderBs []byte
|
renderBs []byte
|
||||||
@ -58,7 +60,8 @@ func initNew() {
|
|||||||
return fmt.Errorf("get work dir err")
|
return fmt.Errorf("get work dir err")
|
||||||
}
|
}
|
||||||
|
|
||||||
projectDir = path.Join(pwd, args[0])
|
moduleName = args[0]
|
||||||
|
projectDir = path.Join(pwd, path.Base(args[0]))
|
||||||
|
|
||||||
if _, err = os.Stat(projectDir); !errors.Is(err, os.ErrNotExist) {
|
if _, err = os.Stat(projectDir); !errors.Is(err, os.ErrNotExist) {
|
||||||
return fmt.Errorf("project folder already exist")
|
return fmt.Errorf("project folder already exist")
|
||||||
@ -101,7 +104,8 @@ func initNew() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if renderBs, err = tp.RenderVar(initBs, map[string]any{
|
if renderBs, err = tp.RenderVar(initBs, map[string]any{
|
||||||
"PROJECT_NAME": args[0],
|
"PROJECT_NAME": projectDir,
|
||||||
|
"MODULE_NAME": moduleName,
|
||||||
}); err != nil {
|
}); err != nil {
|
||||||
return fmt.Errorf("render template init script err: %v", err)
|
return fmt.Errorf("render template init script err: %v", err)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user