MCPcopy Index your code
hub / github.com/perkeep/perkeep / newRootFromConfig

Function newRootFromConfig

pkg/server/root.go:86–164  ·  view source on GitHub ↗
(ld blobserver.Loader, conf jsonconfig.Obj)

Source from the content-addressed store, hash-verified

84}
85
86func newRootFromConfig(ld blobserver.Loader, conf jsonconfig.Obj) (h http.Handler, err error) {
87 checkType := func(key string, htype string) {
88 v := conf.OptionalString(key, "")
89 if v == "" {
90 return
91 }
92 ct := ld.GetHandlerType(v)
93 if ct == "" {
94 err = fmt.Errorf("root handler's %q references non-existent %q", key, v)
95 } else if ct != htype {
96 err = fmt.Errorf("root handler's %q references %q of type %q; expected type %q", key, v, ct, htype)
97 }
98 }
99 checkType("searchRoot", "search")
100 checkType("jsonSignRoot", "jsonsign")
101 if err != nil {
102 return
103 }
104 username, _ := getUserName()
105 root := &RootHandler{
106 BlobRoot: conf.OptionalString("blobRoot", ""),
107 SearchRoot: conf.OptionalString("searchRoot", ""),
108 JSONSignRoot: conf.OptionalString("jsonSignRoot", ""),
109 OwnerName: conf.OptionalString("ownerName", username),
110 Username: osutil.Username(),
111 Prefix: ld.MyPrefix(),
112 }
113 root.Stealth = conf.OptionalBool("stealth", false)
114 root.statusRoot = conf.OptionalString("statusRoot", "")
115 root.helpRoot = conf.OptionalString("helpRoot", "")
116 root.shareRoot = conf.OptionalString("shareRoot", "")
117 if err = conf.Validate(); err != nil {
118 return
119 }
120
121 if root.BlobRoot != "" {
122 bs, err := ld.GetStorage(root.BlobRoot)
123 if err != nil {
124 return nil, fmt.Errorf("Root handler's blobRoot of %q error: %v", root.BlobRoot, err)
125 }
126 root.Storage = bs
127 }
128
129 if root.JSONSignRoot != "" {
130 h, _ := ld.GetHandler(root.JSONSignRoot)
131 if sigh, ok := h.(*signhandler.Handler); ok {
132 root.sigh = sigh
133 }
134 }
135
136 root.searchInit = func() {}
137 if root.SearchRoot != "" {
138 prefix := root.SearchRoot
139 if t := ld.GetHandlerType(prefix); t != "search" {
140 if t == "" {
141 return nil, fmt.Errorf("root handler's searchRoot of %q is invalid and doesn't refer to a declared handler", prefix)
142 }
143 return nil, fmt.Errorf("root handler's searchRoot of %q is of type %q, not %q", prefix, t, "search")

Callers

nothing calls this directly

Calls 9

UsernameFunction · 0.92
getUserNameFunction · 0.85
GetHandlerTypeMethod · 0.65
MyPrefixMethod · 0.65
GetStorageMethod · 0.65
GetHandlerMethod · 0.65
FatalfMethod · 0.65
FindHandlerByTypeMethod · 0.65
HasLegacySHA1Method · 0.45

Tested by

no test coverage detected