diff --git a/file/outline.go b/file/outline.go new file mode 100755 index 0000000..2f1cfea --- /dev/null +++ b/file/outline.go @@ -0,0 +1,50 @@ +// Copyright (c) 2014, B3log +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package file + +import ( + "encoding/json" + "go/ast" + "go/parser" + "go/token" + "net/http" + + "github.com/b3log/wide/util" +) + +// GetOutline gets outfile of a go file. +func GetOutline(w http.ResponseWriter, r *http.Request) { + data := map[string]interface{}{"succ": true} + defer util.RetJSON(w, r, data) + + var args map[string]interface{} + + if err := json.NewDecoder(r.Body).Decode(&args); err != nil { + logger.Error(err) + data["succ"] = false + + return + } + + code := args["code"].(string) + + fset := token.NewFileSet() + f, err := parser.ParseFile(fset, "", code, 0) + if err != nil { + panic(err) + } + + ast.Print(fset, f) +} diff --git a/main.go b/main.go index 0025387..84e8822 100644 --- a/main.go +++ b/main.go @@ -133,6 +133,9 @@ func main() { http.HandleFunc(conf.Wide.Context+"/file/search/text", handlerWrapper(file.SearchText)) http.HandleFunc(conf.Wide.Context+"/file/find/name", handlerWrapper(file.Find)) + // outline + http.HandleFunc(conf.Wide.Context+"/outline", handlerWrapper(file.GetOutline)) + // file export/import http.HandleFunc(conf.Wide.Context+"/file/zip/new", handlerWrapper(file.CreateZip)) http.HandleFunc(conf.Wide.Context+"/file/zip", handlerWrapper(file.GetZip)) diff --git a/output/namespace_linux.go b/output/namespace_linux.go index 6281790..f8bab9e 100644 --- a/output/namespace_linux.go +++ b/output/namespace_linux.go @@ -24,7 +24,7 @@ func setNamespace(cmd *exec.Cmd) { cmd.SysProcAttr = &syscall.SysProcAttr{} //cmd.SysProcAttr.Cloneflags = syscall.CLONE_NEWUSER | syscall.CLONE_NEWNS | syscall.CLONE_NEWUTS | syscall.CLONE_NEWPID | syscall.CLONE_NEWIPC | syscall.CLONE_NEWNET - cmd.SysProcAttr.Cloneflags = syscall.CLONE_NEWUSER | syscall.CLONE_NEWNS | syscall.CLONE_NEWUTS | syscall.CLONE_NEWPID | syscall.CLONE_NEWIPC + cmd.SysProcAttr.Cloneflags = syscall.CLONE_NEWUSER /*| syscall.CLONE_NEWNS*/ | syscall.CLONE_NEWUTS | syscall.CLONE_NEWPID | syscall.CLONE_NEWIPC /*| syscall.CLONE_NEWNET*/ cmd.SysProcAttr.Credential = &syscall.Credential{ Uid: 0, Gid: 0,