feat: upgrading echo, removing makefile
This commit is contained in:
parent
89750fbfca
commit
63c52f19e2
6 changed files with 60 additions and 24 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
vendor/
|
4
Makefile
4
Makefile
|
@ -1,4 +0,0 @@
|
||||||
default: static
|
|
||||||
|
|
||||||
static:
|
|
||||||
docker run --rm -v $(shell pwd):/src centurylink/golang-builder
|
|
37
glide.lock
generated
Normal file
37
glide.lock
generated
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
hash: ff8a32679991a0939800d56b0b34ade1a46ed2f6d9a6f21a95e07196b5e16fbe
|
||||||
|
updated: 2017-05-27T20:48:09.06190059+02:00
|
||||||
|
imports:
|
||||||
|
- name: github.com/dgrijalva/jwt-go
|
||||||
|
version: 6c8dedd55f8a2e41f605de6d5d66e51ed1f299fc
|
||||||
|
- name: github.com/labstack/echo
|
||||||
|
version: 1049c9613cd371b7ea8f219404c9a821734781ed
|
||||||
|
subpackages:
|
||||||
|
- '...'
|
||||||
|
- middleware
|
||||||
|
- name: github.com/labstack/gommon
|
||||||
|
version: 1121fd3e243c202482226a7afe4dcd07ffc4139a
|
||||||
|
subpackages:
|
||||||
|
- bytes
|
||||||
|
- color
|
||||||
|
- log
|
||||||
|
- random
|
||||||
|
- name: github.com/mattn/go-colorable
|
||||||
|
version: ded68f7a9561c023e790de24279db7ebf473ea80
|
||||||
|
- name: github.com/mattn/go-isatty
|
||||||
|
version: fc9e8d8ef48496124e79ae0df75490096eccf6fe
|
||||||
|
- name: github.com/PierreZ/tlscert
|
||||||
|
version: 132262881d39c577835ab78f179abd2de116cb32
|
||||||
|
- name: github.com/valyala/bytebufferpool
|
||||||
|
version: e746df99fe4a3986f4d4f79e13c1e0117ce9c2f7
|
||||||
|
- name: github.com/valyala/fasttemplate
|
||||||
|
version: dcecefd839c4193db0d35b88ec65b4c12d360ab0
|
||||||
|
- name: golang.org/x/crypto
|
||||||
|
version: 7e9105388ebff089b3f99f0ef676ea55a6da3a7e
|
||||||
|
subpackages:
|
||||||
|
- acme
|
||||||
|
- acme/autocert
|
||||||
|
- name: golang.org/x/sys
|
||||||
|
version: a55a76086885b80f79961eacb876ebd8caf3868d
|
||||||
|
subpackages:
|
||||||
|
- unix
|
||||||
|
testImports: []
|
8
glide.yaml
Normal file
8
glide.yaml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
package: github.com/PierreZ/goStatic
|
||||||
|
import:
|
||||||
|
- package: github.com/labstack/echo
|
||||||
|
version: ^3.1.0
|
||||||
|
subpackages:
|
||||||
|
- '...'
|
||||||
|
- middleware
|
||||||
|
- package: github.com/PierreZ/tlscert
|
BIN
goStatic
BIN
goStatic
Binary file not shown.
28
main.go
28
main.go
|
@ -11,7 +11,7 @@ import (
|
||||||
|
|
||||||
"github.com/PierreZ/tlscert"
|
"github.com/PierreZ/tlscert"
|
||||||
"github.com/labstack/echo"
|
"github.com/labstack/echo"
|
||||||
mw "github.com/labstack/echo/middleware"
|
"github.com/labstack/echo/middleware"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
@ -19,34 +19,29 @@ var (
|
||||||
portPtr = flag.Int("p", 8043, "The listening port")
|
portPtr = flag.Int("p", 8043, "The listening port")
|
||||||
pathPtr = flag.String("static", "/srv/http", "The path for the static files")
|
pathPtr = flag.String("static", "/srv/http", "The path for the static files")
|
||||||
crtPtr = flag.String("crt", "/etc/ssl/server", "Folder for server.pem and key.pem")
|
crtPtr = flag.String("crt", "/etc/ssl/server", "Folder for server.pem and key.pem")
|
||||||
HTTPPtr = flag.Bool("forceHTTP", false, "Forcing HTTP and not HTTPS")
|
isUnsecure = flag.Bool("forceHTTP", false, "Forcing HTTP and not HTTPS")
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
|
|
||||||
// Echo instance
|
|
||||||
e := echo.New()
|
e := echo.New()
|
||||||
|
|
||||||
// Middleware
|
// Root level middleware
|
||||||
e.Use(mw.Logger())
|
e.Use(middleware.Logger())
|
||||||
e.Use(mw.Recover())
|
e.Use(middleware.Recover())
|
||||||
|
|
||||||
// Routes
|
|
||||||
e.Static("/", *pathPtr)
|
|
||||||
|
|
||||||
log.Println("Starting goStatic")
|
|
||||||
|
|
||||||
|
e.Static("/", *pathPtr) // Serve everything from the current dir
|
||||||
port := ":" + strconv.FormatInt(int64(*portPtr), 10)
|
port := ":" + strconv.FormatInt(int64(*portPtr), 10)
|
||||||
path := *crtPtr
|
path := *crtPtr
|
||||||
|
|
||||||
// Start server with unsecure HTTP
|
// Start server with unsecure HTTP
|
||||||
if *HTTPPtr {
|
if *isUnsecure {
|
||||||
log.Println("Starting serving", *pathPtr, "on", *portPtr)
|
log.Println("Starting serving", *pathPtr, "on", *portPtr)
|
||||||
e.Run(port)
|
e.Start(port)
|
||||||
// or with awesome TLS
|
|
||||||
} else {
|
} else { // or with awesome TLS
|
||||||
if _, err := os.Stat(path + "/cert.pem"); os.IsNotExist(err) {
|
if _, err := os.Stat(path + "/cert.pem"); os.IsNotExist(err) {
|
||||||
// Generating certificates
|
// Generating certificates
|
||||||
err := tlscert.GenerateCert(path)
|
err := tlscert.GenerateCert(path)
|
||||||
|
@ -56,7 +51,6 @@ func main() {
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Println("Starting serving", *pathPtr, "on", *portPtr)
|
log.Println("Starting serving", *pathPtr, "on", *portPtr)
|
||||||
e.RunTLS(port, path+"/cert.pem", path+"/key.pem")
|
e.StartTLS(port, path+"/cert.pem", path+"/key.pem")
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue