-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplain.go
More file actions
38 lines (31 loc) · 667 Bytes
/
Copy pathplain.go
File metadata and controls
38 lines (31 loc) · 667 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package plain
import (
"os"
"path"
)
type Options struct {
Host string
Port int
WorkingDir string
ReadPageFile ReadPageFileFunc
}
// New initializes server with provided options
func New(o Options) (*Server, error) {
pagesPath := path.Join(o.WorkingDir, pagesDir)
if _, err := os.Stat(pagesPath); os.IsNotExist(err) {
return nil, err
}
s := &Server{
Host: o.Host,
Port: o.Port,
WorkingDir: o.WorkingDir,
pagesPath: pagesPath,
readPageFile: o.ReadPageFile,
}
var err error
s.routes, err = getRoutes(s.pagesPath, s.WorkingDir, s.readPageFile)
if err != nil {
return nil, err
}
return s, nil
}