forked from tideland/golib
-
Notifications
You must be signed in to change notification settings - Fork 0
/
options.go
79 lines (68 loc) · 1.77 KB
/
options.go
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Tideland Go Library - Web - Options
//
// Copyright (C) 2009-2015 Frank Mueller / Tideland / Oldenburg / Germany
//
// All rights reserved. Use of this source code is governed
// by the new BSD license.
package web
//--------------------
// IMPORTS
//--------------------
import ()
//--------------------
// OPTIONS
//--------------------
const (
defaultBasePath = "/"
defaultDefaultDomain = "default"
defaultDefaultResource = "default"
)
// Option defines a function setting an option for a system
// like the server or the multiplexer.
type Option func(mux Multiplexer) error
// BasePath sets the path thats used as prefix before
// domain and resource.
func BasePath(basePath string) Option {
return func(mux Multiplexer) error {
if basePath == "" {
basePath = defaultBasePath
}
if basePath[len(basePath)-1] != '/' {
basePath += "/"
}
m := mux.(*multiplexer)
m.basePath = basePath
return nil
}
}
// DefaultDomainResource sets the default domain and resource.
func DefaultDomainResource(defaultDomain, defaultResource string) Option {
return func(mux Multiplexer) error {
if defaultDomain == "" {
defaultDomain = defaultDefaultDomain
}
if defaultResource == "" {
defaultResource = defaultDefaultResource
}
m := mux.(*multiplexer)
m.defaultDomain = defaultDomain
m.defaultResource = defaultResource
return nil
}
}
// Scenes sets the scene manager of the multiplexer.
func Scenes(sm SceneManager) Option {
return func(mux Multiplexer) error {
m := mux.(*multiplexer)
m.sceneManager = sm
return nil
}
}
// Handlers allows to register multiple handlers direct at creation
// of the server.
func Handlers(registrations Registrations) Option {
return func(mux Multiplexer) error {
return mux.RegisterAll(registrations)
}
}
// EOF