Skip to content

Commit

Permalink
/move model/ view/ into application. +data/.
Browse files Browse the repository at this point in the history
  • Loading branch information
nicerobot committed Jul 25, 2016
1 parent c6d21d5 commit d25b2e9
Show file tree
Hide file tree
Showing 21 changed files with 86 additions and 24 deletions.
22 changes: 11 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ build $(APP_NAME): $(SOURCE) ## Build opinionated
run: $(APP_NAME) ## Run opinionated
./$(APP_NAME)

cert:
openssl req -new -sha256 -key server.key -out server.csr
openssl x509 -req -sha256 -in server.csr -signkey server.key -out server.crt -days 3650
cert: data/server.csr

data/server.csr: data/server.key
cd $(dir $@); openssl req -new -sha256 -key server.key -out server.csr -config example.conf
cd $(dir $@); openssl x509 -req -sha256 -in server.csr -signkey server.key -out server.crt -days 3650

ecdsa:
openssl req -x509 -nodes -newkey ec:secp384r1 -keyout server.ecdsa.key -out server.ecdsa.crt -days 3650
ln -sf server.ecdsa.key server.key
ln -sf server.ecdsa.crt server.crt

rsa:
openssl req -x509 -nodes -newkey rsa:2048 -keyout server.rsa.key -out server.rsa.crt -days 3650
ln -sf server.rsa.key server.key
ln -sf server.rsa.crt server.crt
cd data; openssl req -x509 -nodes -newkey ec:secp384r1 -keyout server.ecdsa.key -out server.ecdsa.crt -days 3650
cd data; ln -sf server.ecdsa.key server.key; ln -sf server.ecdsa.crt server.crt

data/server.key:
cd $(dir $@); openssl req -x509 -nodes -newkey rsa:2048 -keyout server.rsa.key -out server.rsa.crt -days 3650 -config example.conf
cd $(dir $@); ln -sf server.rsa.key server.key; ln -sf server.rsa.crt server.crt


help: ## This help.
Expand Down
Empty file added data/.gitkeep
Empty file.
13 changes: 13 additions & 0 deletions data/example.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[ req ]
default_bits = 4096
prompt = no
default_md = sha2
distinguished_name = dn

[ dn ]
C=US
ST=WA
L=Seattle
O=Example Co.
CN=*.example.com
[email protected]
Empty file added test/README.md
Empty file.
Empty file added vendor/application/README.md
Empty file.
43 changes: 42 additions & 1 deletion vendor/application/settings.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package application

import "net/url"
import (
"log"
"net/url"
"os"
"os/exec"
"path/filepath"
)

//
var Settings struct {
Expand All @@ -16,5 +22,40 @@ var Settings struct {
Powered string
Version string

Program struct {
Name string
Folder string
Full string
Data string
}

Docs *url.URL
}

//
func init() {
Settings.Program.Full = os.Args[0]
Settings.Program.Name = filepath.Base(Settings.Program.Full)

if dir, _ := filepath.Split(Settings.Program.Full); dir == "" {
if path, err := exec.LookPath(Settings.Program.Full); err != nil {
log.Println(err)
} else {
Settings.Program.Folder = filepath.Base(path)
}
} else if ln, err := filepath.EvalSymlinks(Settings.Program.Full); err != nil {
log.Println(err)
} else {
if dir, err := filepath.Abs(filepath.Dir(ln)); err != nil {
log.Println(err)
} else {
Settings.Program.Folder = dir
}
}

data := os.Getenv("DATA")
if data == "" {
data = "data"
}
Settings.Program.Data = filepath.Join(Settings.Program.Folder, data)
}
32 changes: 20 additions & 12 deletions vendor/application/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
stderr "log"
"net/http"
"path/filepath"
"strconv"
"time"
)
Expand All @@ -29,26 +30,33 @@ func Start() error {
Handler: mux,
}

fmt.Println("listening on " + srv.Addr)
message := "listening on " + srv.Addr

if Settings.Insecure {

fmt.Printf("HTTP %s\n", message)
return srv.ListenAndServe()

} else if cert, err := tls.LoadX509KeyPair("server.crt", "server.key"); err != nil {
stderr.Println(err)
} else {
crt := filepath.Join(Settings.Program.Data, "server.crt")
key := filepath.Join(Settings.Program.Data, "server.key")

return srv.ListenAndServe()
if cert, err := tls.LoadX509KeyPair(crt, key); err != nil {
stderr.Println(err)

} else {
fmt.Printf("HTTP %s\n", message)
return srv.ListenAndServe()

srv.TLSConfig = &tls.Config{
Certificates: []tls.Certificate{
cert,
},
}
} else {

return srv.ListenAndServeTLS("server.crt", "server.key")
}
srv.TLSConfig = &tls.Config{
Certificates: []tls.Certificate{
cert,
},
}

fmt.Printf("HTTPS %s\n", message)
return srv.ListenAndServeTLS(crt, key)
}
}
}
Empty file.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Empty file.
Empty file.
File renamed without changes.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.
Empty file.

0 comments on commit d25b2e9

Please sign in to comment.