This repository has been archived by the owner on Jul 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add `gen` command and basic FE * Add Headers and RawParams and Auth in FE * Minor Updates * 🔥 Moved the whole to markdown and docsify * 📝 Add autobrowser open and Updated Readme * Final Touches for Stuffing and deployment Co-authored-by: Joice M. Joseph <joice@moolekkari.net> * Minor Refactor to Code and Docs * meaningful name for fstructm, renamed to FileTrunk. removed named variable definition in FileTrunk * Add Flag for Auto Browser Open * 📝 Updated Docs on Broswer Flag Co-authored-by: Joice M. Joseph <joice@moolekkari.net>
- Loading branch information
1 parent
f1b75a1
commit 7bc2111
Showing
12 changed files
with
429 additions
and
40 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 |
---|---|---|
|
@@ -10,6 +10,8 @@ | |
*.so | ||
*.dylib | ||
hopp-cli | ||
hoop.bin | ||
dist/ | ||
|
||
# Test binary, built with `go test -c` | ||
*.test | ||
|
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
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,91 @@ | ||
package methods | ||
|
||
import ( | ||
"bytes" | ||
"fmt" | ||
"log" | ||
"net/http" | ||
"os" | ||
"strconv" | ||
"time" | ||
|
||
"github.com/knadh/stuffbin" | ||
"github.com/pkg/browser" | ||
"github.com/urfave/cli" | ||
) | ||
|
||
//FileTrunk handles the buffer for generated README.md File | ||
type FileTrunk struct{ bytes.Buffer } | ||
|
||
// Name holds the FileName, here README.md | ||
func (f *FileTrunk) Name() string { return "README.md" } | ||
|
||
// Size holds the size of the File | ||
func (f *FileTrunk) Size() int64 { return int64(f.Len()) } | ||
|
||
// Mode holds the file Mode | ||
func (f *FileTrunk) Mode() os.FileMode { return 0755 } | ||
|
||
// ModTime holds creation time of File | ||
func (f *FileTrunk) ModTime() time.Time { return time.Now() } | ||
|
||
// IsDir checks if True | ||
func (f *FileTrunk) IsDir() bool { return false } | ||
|
||
// Sys - I have no idea | ||
func (f *FileTrunk) Sys() interface{} { return nil } | ||
|
||
//GenerateDocs generates the Documentation site from the hoppscotch-collection.json | ||
func GenerateDocs(c *cli.Context) error { | ||
execPath, err := os.Executable() //get Executable Path for StuffBin | ||
if err != nil { | ||
return err | ||
} | ||
fs, err := initFileSystem(execPath) //Init Virtual FS | ||
if err != nil { | ||
return err | ||
} | ||
|
||
colls, err := ReadCollection(c.Args().Get(0)) | ||
if err != nil { | ||
return err | ||
} | ||
// FuncMap for the HTML template | ||
fmap := map[string]interface{}{ | ||
"html": func(val string) string { return val }, | ||
} | ||
|
||
t, err := stuffbin.ParseTemplates(fmap, fs, "/template.md") | ||
|
||
// f will be used to store rendered templates in memory. | ||
var f FileTrunk | ||
|
||
// Execute the template to the file. | ||
if err = t.Execute(&f, colls); err != nil { | ||
return err | ||
} | ||
|
||
if err := fs.Add(stuffbin.NewFile("/README.md", &f, f.Bytes())); err != nil { | ||
return err | ||
} | ||
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { | ||
out, err := fs.Read("templates/index.html") | ||
if err != nil { | ||
log.Println(err) | ||
} | ||
w.Write(out) | ||
}) | ||
PortStr := ":" + strconv.Itoa(c.Int("port")) | ||
URL := fmt.Sprintf("http://localhost%s", PortStr) | ||
|
||
http.Handle("/static/", http.StripPrefix("/static/", fs.FileServer())) | ||
|
||
log.Printf("\033[1;36mServer Listening at %s\033[0m", URL) | ||
|
||
if !c.Bool("browser") { //Check if User wants to open the Broswer | ||
browser.OpenURL(URL) // AutoOpen the Broswer | ||
} | ||
|
||
http.ListenAndServe(PortStr, nil) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package methods | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/knadh/stuffbin" | ||
) | ||
|
||
func initFileSystem(binPath string) (stuffbin.FileSystem, error) { | ||
fs, err := stuffbin.UnStuff(binPath) | ||
// If files are not stuffed with the binary, | ||
// try to pick up files from local file system. | ||
if err == stuffbin.ErrNoID { | ||
// Running in local mode. Load the required static assets into | ||
// the in-memory stuffbin.FileSystem. | ||
|
||
files := []string{ | ||
"./templates/index.html", | ||
"./templates/template.md:/template.md", | ||
} | ||
|
||
// mutates err object. | ||
fs, err = stuffbin.NewLocalFS("/", files...) | ||
if err != nil { | ||
log.Println("Error in Virtual FS", err) | ||
} | ||
} | ||
|
||
// Either unstuff or NewLocalFS throws error, | ||
// mutated error value will be returned | ||
return fs, err | ||
} |
Oops, something went wrong.