Skip to content

Commit

Permalink
Chdir to config directory
Browse files Browse the repository at this point in the history
  • Loading branch information
phonkee committed Jul 22, 2015
1 parent 4a2ee8c commit 6683f55
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
7 changes: 7 additions & 0 deletions cmd/goexpose/goexpose.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,18 @@ func main() {
err error
)

// read config file
if config, err = goexpose.NewConfigFromFilename(*configVar); err != nil {
glog.Errorf("config error: %v", err)
os.Exit(1)
}

// change working directory to config directory
if err = os.Chdir(config.Directory); err != nil {
glog.Errorf("config error: %v", err)
os.Exit(1)
}

if server, err = goexpose.NewServer(config); err != nil {
glog.Errorf("server error: %v", err)
os.Exit(1)
Expand Down
17 changes: 13 additions & 4 deletions config.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package goexpose

import (
"crypto/sha256"
"encoding/json"
"fmt"
"io"
"io/ioutil"
"net/http"
"path/filepath"
"regexp"
"strings"
"crypto/sha256"
"io"
)

/*
Expand All @@ -17,7 +18,9 @@ Returns filename from file
func NewConfigFromFilename(filename string) (config *Config, err error) {
config = NewConfig()

var result []byte
var (
result []byte
)
if result, err = ioutil.ReadFile(filename); err != nil {
return
}
Expand All @@ -27,6 +30,11 @@ func NewConfigFromFilename(filename string) (config *Config, err error) {
return
}

// get config dir
if config.Directory, err = filepath.Abs(filepath.Dir(filename)); err != nil {
return
}

return
}

Expand All @@ -51,6 +59,7 @@ type Config struct {
Authorizers map[string]*AuthorizerConfig `json:"authorizers"`
Endpoints []*EndpointConfig `json:"endpoints"`
ReloadEnv bool `json:"reload_env"`
Directory string `json:"-"`
}

/*
Expand Down Expand Up @@ -102,7 +111,7 @@ func (e *EndpointConfig) Validate() (err error) {
return
}

func (e *EndpointConfig ) RouteName() string {
func (e *EndpointConfig) RouteName() string {
hash := sha256.New()
io.WriteString(hash, e.Path)
return fmt.Sprintf("%x", hash.Sum(nil))
Expand Down

0 comments on commit 6683f55

Please sign in to comment.