mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 02:31:04 +01:00
Do not create the global configuration in homedir by-default, as, correctly, requested on chat. Use iris.WithGlobalConfiguration with a pre-defined iris.yml file on your home directory, existing users will not have any issues, new one will have to create the file before
Former-commit-id: 033f7e96693b13f87b44b445ed166328fea6e0a0
This commit is contained in:
parent
66d367b255
commit
fc0f27c4fc
|
@ -116,7 +116,7 @@ func main() {
|
|||
app.Get("/echo", ws.Handler())
|
||||
|
||||
// serve the javascript built'n client-side library,
|
||||
// see weboskcets.html script tags, this path is used.
|
||||
// see websockets.html script tags, this path is used.
|
||||
app.Any("/iris-ws.js", func(ctx iris.Context) {
|
||||
ctx.Write(websocket.ClientSource)
|
||||
})
|
||||
|
|
|
@ -36,7 +36,7 @@ func setupWebsocket(app *iris.Application) {
|
|||
app.Get("/echo", ws.Handler())
|
||||
|
||||
// serve the javascript built'n client-side library,
|
||||
// see weboskcets.html script tags, this path is used.
|
||||
// see websockets.html script tags, this path is used.
|
||||
app.Any("/iris-ws.js", func(ctx iris.Context) {
|
||||
ctx.Write(websocket.ClientSource)
|
||||
})
|
||||
|
|
|
@ -26,7 +26,7 @@ func main() {
|
|||
app.Get("/my_endpoint", ws.Handler())
|
||||
|
||||
// serve the javascript built'n client-side library,
|
||||
// see weboskcets.html script tags, this path is used.
|
||||
// see websockets.html script tags, this path is used.
|
||||
app.Any("/iris-ws.js", func(ctx iris.Context) {
|
||||
ctx.Write(websocket.ClientSource)
|
||||
})
|
||||
|
|
|
@ -27,7 +27,7 @@ func main() {
|
|||
app.Get("/my_endpoint", ws.Handler())
|
||||
|
||||
// serve the javascript built'n client-side library,
|
||||
// see weboskcets.html script tags, this path is used.
|
||||
// see websockets.html script tags, this path is used.
|
||||
app.Any("/iris-ws.js", func(ctx iris.Context) {
|
||||
ctx.Write(websocket.ClientSource)
|
||||
})
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"runtime"
|
||||
|
||||
"github.com/BurntSushi/toml"
|
||||
"github.com/kataras/golog"
|
||||
"gopkg.in/yaml.v2"
|
||||
|
||||
"github.com/kataras/iris/context"
|
||||
|
@ -17,8 +16,6 @@ import (
|
|||
|
||||
const globalConfigurationKeyword = "~"
|
||||
|
||||
var globalConfigurationExisted = false
|
||||
|
||||
// homeConfigurationFilename returns the physical location of the global configuration(yaml or toml) file.
|
||||
// This is useful when we run multiple iris servers that share the same
|
||||
// configuration, even with custom values at its "Other" field.
|
||||
|
@ -28,28 +25,6 @@ func homeConfigurationFilename(ext string) string {
|
|||
return filepath.Join(homeDir(), "iris"+ext)
|
||||
}
|
||||
|
||||
func init() {
|
||||
filename := homeConfigurationFilename(".yml")
|
||||
c, err := parseYAML(filename)
|
||||
if err != nil {
|
||||
// this error will be occurred the first time that the configuration
|
||||
// file doesn't exist.
|
||||
// Create the YAML-ONLY global configuration file now using the default configuration 'c'.
|
||||
// This is useful when we run multiple iris servers that share the same
|
||||
// configuration, even with custom values at its "Other" field.
|
||||
out, err := yaml.Marshal(&c)
|
||||
|
||||
if err == nil {
|
||||
err = ioutil.WriteFile(filename, out, os.FileMode(0666))
|
||||
}
|
||||
if err != nil {
|
||||
golog.Debugf("error while writing the global configuration field at: %s. Trace: %v\n", filename, err)
|
||||
}
|
||||
} else {
|
||||
globalConfigurationExisted = true
|
||||
}
|
||||
}
|
||||
|
||||
func homeDir() (home string) {
|
||||
u, err := user.Current()
|
||||
if u != nil && err == nil {
|
||||
|
|
|
@ -6,6 +6,8 @@ import (
|
|||
"reflect"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
// $ go test -v -run TestConfiguration*
|
||||
|
@ -89,7 +91,30 @@ func TestConfigurationOptionsDeep(t *testing.T) {
|
|||
t.Fatalf("DEEP configuration is not the same after New expected:\n %#v \ngot:\n %#v", expected, has)
|
||||
}
|
||||
}
|
||||
|
||||
func createGlobalConfiguration(t *testing.T) {
|
||||
filename := homeConfigurationFilename(".yml")
|
||||
c, err := parseYAML(filename)
|
||||
if err != nil {
|
||||
// this error will be occurred the first time that the configuration
|
||||
// file doesn't exist.
|
||||
// Create the YAML-ONLY global configuration file now using the default configuration 'c'.
|
||||
// This is useful when we run multiple iris servers that share the same
|
||||
// configuration, even with custom values at its "Other" field.
|
||||
out, err := yaml.Marshal(&c)
|
||||
|
||||
if err == nil {
|
||||
err = ioutil.WriteFile(filename, out, os.FileMode(0666))
|
||||
}
|
||||
if err != nil {
|
||||
t.Fatalf("error while writing the global configuration field at: %s. Trace: %v\n", filename, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestConfigurationGlobal(t *testing.T) {
|
||||
createGlobalConfiguration(t)
|
||||
|
||||
testConfigurationGlobal(t, WithGlobalConfiguration)
|
||||
// globalConfigurationKeyword = "~""
|
||||
testConfigurationGlobal(t, WithConfiguration(YAML(globalConfigurationKeyword)))
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package maintenance
|
||||
|
||||
// Start starts the maintenance process.
|
||||
func Start(globalConfigurationExisted bool) {
|
||||
CheckForUpdates(!globalConfigurationExisted)
|
||||
func Start() {
|
||||
CheckForUpdates()
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ const (
|
|||
|
||||
// CheckForUpdates checks for any available updates
|
||||
// and asks for the user if want to update now or not.
|
||||
func CheckForUpdates(ft bool) {
|
||||
func CheckForUpdates() {
|
||||
v := version.Acquire()
|
||||
updateAvailale := v.Compare(Version) == version.Smaller
|
||||
|
||||
|
|
2
doc.go
2
doc.go
|
@ -1416,7 +1416,7 @@ Example Server Code:
|
|||
app.Get("/echo", ws.Handler())
|
||||
|
||||
// serve the javascript built'n client-side library,
|
||||
// see weboskcets.html script tags, this path is used.
|
||||
// see websockets.html script tags, this path is used.
|
||||
app.Any("/iris-ws.js", func(ctx iris.Context) {
|
||||
ctx.Write(websocket.ClientSource)
|
||||
})
|
||||
|
|
2
iris.go
2
iris.go
|
@ -771,7 +771,7 @@ func (app *Application) Run(serve Runner, withOrWithout ...Configurator) error {
|
|||
app.logger.Debugf("Application: running using %d host(s)", len(app.Hosts)+1)
|
||||
|
||||
if !app.config.DisableVersionChecker {
|
||||
go maintenance.Start(globalConfigurationExisted)
|
||||
go maintenance.Start()
|
||||
}
|
||||
|
||||
// this will block until an error(unless supervisor's DeferFlow called from a Task).
|
||||
|
|
|
@ -53,7 +53,7 @@ Example code:
|
|||
app.Get("/echo", ws.Handler())
|
||||
|
||||
// serve the javascript built'n client-side library,
|
||||
// see weboskcets.html script tags, this path is used.
|
||||
// see websockets.html script tags, this path is used.
|
||||
app.Any("/iris-ws.js", func(ctx context.Context) {
|
||||
ctx.Write(websocket.ClientSource)
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue
Block a user