Skip to content

Commit 3965925

Browse files
committed
fixes
1 parent dd81476 commit 3965925

File tree

1 file changed

+37
-29
lines changed

1 file changed

+37
-29
lines changed

datastore.go

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,18 @@ type Settings interface {
5757
IsDevelopment() bool
5858
}
5959

60+
func (ds *Datastore) TurnOnLogging() {
61+
dat.SetDebugLogger(ds.Logger.Warnf)
62+
dat.SetSQLLogger(ds.Logger.Infof)
63+
dat.SetErrorLogger(ds.Logger.Errorf)
64+
}
65+
66+
func (ds *Datastore) TurnOffLogging() {
67+
dat.SetDebugLogger(nil)
68+
dat.SetSQLLogger(nil)
69+
dat.SetErrorLogger(nil)
70+
}
71+
6072
// type Logger struct {
6173
// errLog string
6274
// }
@@ -103,6 +115,30 @@ type Settings interface {
103115
func New(logger Logger, ws Websocket) *Datastore {
104116
store := Simple()
105117
store.Logger = logger
118+
119+
logger.Info("Current IP Addresses")
120+
ifaces, err := net.Interfaces()
121+
if err != nil {
122+
logger.Error("Failed to load interfaces", err)
123+
}
124+
for _, i := range ifaces {
125+
addrs, err := i.Addrs()
126+
if err != nil {
127+
logger.Error("Failed to load addresses", err)
128+
}
129+
// handle err
130+
for _, addr := range addrs {
131+
var ip net.IP
132+
switch v := addr.(type) {
133+
case *net.IPNet:
134+
ip = v.IP
135+
case *net.IPAddr:
136+
ip = v.IP
137+
}
138+
logger.Info("ip: ", ip.String())
139+
}
140+
}
141+
106142
store.Cache = getCache(store)
107143
store.DB = getDBConnection(store)
108144
return store
@@ -182,11 +218,8 @@ func getDBConnection(store *Datastore) *runner.DB {
182218
// Should be disabled in production/release builds.
183219
dat.Strict = true
184220

185-
dat.SetDebugLogger(store.Logger.Warnf)
186-
dat.SetSQLLogger(store.Logger.Infof)
187-
dat.SetErrorLogger(store.Logger.Errorf)
188221
// Log any query over 10ms as warnings. (optional)
189-
runner.LogQueriesThreshold = 1 * time.Microsecond // LOG EVERYTHING ON DEV
222+
// runner.LogQueriesThreshold = 1 * time.Microsecond // LOG EVERYTHING ON DEV // turn it off and on with a flag
190223
}
191224

192225
// db connection
@@ -237,31 +270,6 @@ func getCache(store *Datastore) *Cache {
237270
}
238271
}
239272

240-
// func getS3Connection() *s3.S3 {
241-
// id := os.Getenv("AWS_ACCESS_KEY_ID")
242-
// if id == "" {
243-
// log.Error("AWS_ACCESS_KEY_ID not specified")
244-
// }
245-
// key := os.Getenv("AWS_SECRET_ACCESS_KEY")
246-
// if key == "" {
247-
// log.Error("AWS_SECRET_ACCESS_KEY not specified")
248-
// }
249-
// region := os.Getenv("AWS_REGION")
250-
// if region == "" {
251-
// log.Error("AWS_REGION not specified")
252-
// }
253-
// token := ""
254-
255-
// creds := credentials.NewStaticCredentials(id, key, token)
256-
// _, err := creds.Get()
257-
// if err != nil {
258-
// log.Error("AWS authentication error")
259-
// }
260-
// cfg := aws.NewConfig().WithRegion(region).WithCredentials(creds)
261-
// s := s3.New(session.New(), cfg)
262-
// return s
263-
// }
264-
265273
type Cache struct {
266274
Client *xredis.Client
267275
}

0 commit comments

Comments
 (0)