File tree 2 files changed +13
-8
lines changed
2 files changed +13
-8
lines changed Original file line number Diff line number Diff line change @@ -25,14 +25,19 @@ import (
25
25
_ "github.com/mattn/go-sqlite3"
26
26
)
27
27
28
- type Server struct {
28
+ type server struct {
29
29
DB * sql.DB
30
- Host string
30
+ host string
31
31
Key string
32
32
}
33
33
34
+ // Constructor for new server.
35
+ func NewServer (address string ) * server {
36
+ return & server {host : address }
37
+ }
38
+
34
39
// Open and check database connection.
35
- func (s * Server ) OpenDB (path string ) (err error ) {
40
+ func (s * server ) OpenDB (path string ) (err error ) {
36
41
if s .DB , err = sql .Open ("sqlite3" , path ); err != nil {
37
42
return err
38
43
}
@@ -46,7 +51,7 @@ func (s *Server) OpenDB(path string) (err error) {
46
51
}
47
52
48
53
// Running daemon process.
49
- func (s * Server ) Run () {
54
+ func (s * server ) Run () {
50
55
r := mux .NewRouter ().StrictSlash (true )
51
56
52
57
// HTTP handlers
@@ -61,6 +66,6 @@ func (s *Server) Run() {
61
66
}
62
67
63
68
// Listen server on port 8080
64
- log .Printf ("Starting tornote server on %s" , s .Host )
65
- log .Fatal (http .ListenAndServe (s .Host , r ))
69
+ log .Printf ("Starting tornote server on %s" , s .host )
70
+ log .Fatal (http .ListenAndServe (s .host , r ))
66
71
}
Original file line number Diff line number Diff line change @@ -26,7 +26,7 @@ import (
26
26
)
27
27
28
28
var (
29
- addr = flag .String ("addr" , ":8000" , "The address to bind to" )
29
+ address = flag .String ("addr" , ":8000" , "The address and port to listen " )
30
30
db = flag .String ("db" , "./db.sqlite3" , "Path to sqlite3 database" )
31
31
version = flag .Bool ("version" , false , "Print server version" )
32
32
)
@@ -41,7 +41,7 @@ func main() {
41
41
os .Exit (0 )
42
42
}
43
43
44
- server := & tornote.Server { Host : * addr }
44
+ server := tornote .NewServer ( * address )
45
45
46
46
// Connecting to database
47
47
if err := server .OpenDB (* db ); err != nil {
You can’t perform that action at this time.
0 commit comments