func (suite *GraphTestSuite) BenchmarkWrite(t *C) { var err error var info graph.NodeInfo info.ParentId = graph.RootNodeId info.Mode = os.FileMode(0755) info.Type = "application/json" for i := 0; err == nil && i < t.N; i++ { info.Name = fmt.Sprint(i) _, err = suite.ng.NewNodeWithNodeInfo(info) } if err != nil { panic(err) } }
// POST v1/node/{parentId} // body -> {nodeInfo} // returns -> {nodeInfo} func (restApi OlympusApi) CreateNode(writer http.ResponseWriter, req *http.Request) { parent := restApi.graph.NodeWithId(paramFromRequest("parentId", req)) if !parent.Exists() { writeNodeNotFoundError(parent.Id, writer) return } var nodeInfo graph.NodeInfo defer req.Body.Close() decoder := decoderFromHeader(req.Body, req.Header) if err := decoder.Decode(&nodeInfo); err != nil { writer.WriteHeader(http.StatusBadRequest) writer.Write([]byte(err.Error())) return } else if node := restApi.graph.NodeWithName(parent.Id, nodeInfo.Name); node != nil && node.Exists() { http.Error(writer, fmt.Sprintf("Node exists, call /v1/touch/%s/ to update this object", node.Id), http.StatusBadRequest) } else { nodeInfo.ParentId = parent.Id nodeInfo.MTime = time.Now() if nodeInfo.Type == "" { nodeInfo.Type = util.MimeType(nodeInfo.Name) } if newNode, err := restApi.graph.NewNodeWithNodeInfo(nodeInfo); err != nil { http.Error(writer, err.Error(), http.StatusBadRequest) } else { encoder := encoderFromHeader(writer, req.Header) writer.WriteHeader(http.StatusCreated) nodeInfo = newNode.NodeInfo() encoder.Encode(nodeInfo) } } }