HTTP handler for GET _design/$ddoc
()
| 23 | |
| 24 | // HTTP handler for GET _design/$ddoc |
| 25 | func (h *handler) handleGetDesignDoc() error { |
| 26 | ddocID := h.PathVar("ddoc") |
| 27 | var result interface{} |
| 28 | if ddocID == db.DesignDocSyncGateway() { |
| 29 | // we serve this content here so that CouchDB 1.2 has something to |
| 30 | // hash into the replication-id, to correspond to our filter. |
| 31 | filter := "ok" |
| 32 | defaultCollection, err := h.db.GetDefaultDatabaseCollection() |
| 33 | if err != nil { |
| 34 | return err |
| 35 | } |
| 36 | if defaultCollection.ChannelMapper != nil { |
| 37 | hash := sha1.New() |
| 38 | _, _ = io.WriteString(hash, defaultCollection.ChannelMapper.Function()) |
| 39 | filter = fmt.Sprint(hash.Sum(nil)) |
| 40 | } |
| 41 | result = db.Body{"filters": db.Body{"bychannel": filter}} |
| 42 | } else { |
| 43 | var getErr error |
| 44 | result, getErr = h.db.GetDesignDoc(ddocID) |
| 45 | if getErr != nil { |
| 46 | return getErr |
| 47 | } |
| 48 | } |
| 49 | h.writeJSON(result) |
| 50 | return nil |
| 51 | } |
| 52 | |
| 53 | // HTTP handler for PUT _design/$ddoc |
| 54 | func (h *handler) handlePutDesignDoc() error { |
nothing calls this directly
no test coverage detected