func (f file_store_t) SetBlob(name string) (io.WriteCloser, error) { p := path.Join(string(f), name) err := os.MkdirAll(path.Dir(p), 0755) if err != nil { return nil, errors.Forward(err, "Unable to Set() `%s`", name) } w, err := os.Create(p) if err != nil { err = errors.Forward(err, "Unable to Set() `%s`", name) } return w, err }
func Open(u *url.URL) (store.Store, error) { if u.Host != "" { wd, err := os.Getwd() if err != nil { return nil, errors.Forward(err, "Failed to open store at `%s`", u) } u.Path = path.Join(wd, u.Host+u.Path) u.Host = "" } return file_store_t(u.Path), nil }
func (f file_store_t) GetBlob(name string) (io.ReadCloser, error) { r, err := os.Open(path.Join(string(f), name)) if err != nil { if os.IsNotExist(err) { err = store.NotFoundError(name) } else { err = errors.Forward(err, "Unable to Get() `%s`", name) } } return r, err }
func (f Factory) build(c *container_t) error { c.mtx.Lock() defer c.mtx.Unlock() app := &Application{ container: c, dynamic: mux.NewRouter(), } f(app) if app.Name == "" { return errors.Fmt("application name must not be empty.") } if _, p := c.app_map[app.Name]; p { return errors.Fmt("%s: application name must be unique.", app.Name) } if app.Generator == nil { return errors.Fmt("%s: application must have a generator.", app.Name) } app.database = c.database app.src = store.SubStore(c.src, app.Name) app.dst = store.SubStore(c.dst, app.Name) static, err := shttp.NewRouteHandler(store.Cache(app.dst)) if err != nil { return errors.Forward(err, "%s: error while loading the route handler.", app.Name) } app.static = static app.dynamic.NotFoundHandler = static c.router.Add(app) c.apps = append(c.apps, app) c.app_map[app.Name] = app return nil }