diff --git a/editor/editors.go b/editor/editors.go index f227807..28e2530 100644 --- a/editor/editors.go +++ b/editor/editors.go @@ -1,3 +1,4 @@ +// 编辑器操作. package editor import ( @@ -149,6 +150,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) { w.Write(output) } +// 查找声明. func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{"succ": true} defer util.RetJSON(w, r, data) @@ -230,6 +232,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) { data["cursorCh"] = cursorCh } +// 查找使用. func FindUsagesHandler(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{"succ": true} defer util.RetJSON(w, r, data) diff --git a/file/files.go b/file/files.go index f9833cd..7e29262 100644 --- a/file/files.go +++ b/file/files.go @@ -1,3 +1,4 @@ +// 文件树操作. package file import ( @@ -57,6 +58,7 @@ func GetFiles(w http.ResponseWriter, r *http.Request) { data["root"] = root } +// 编辑器打开一个文件. func GetFile(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{"succ": true} defer util.RetJSON(w, r, data) @@ -106,6 +108,7 @@ func GetFile(w http.ResponseWriter, r *http.Request) { } } +// 保存文件. func SaveFile(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{"succ": true} defer util.RetJSON(w, r, data) @@ -144,6 +147,7 @@ func SaveFile(w http.ResponseWriter, r *http.Request) { } } +// 新建文件/目录. func NewFile(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{"succ": true} defer util.RetJSON(w, r, data) @@ -167,6 +171,7 @@ func NewFile(w http.ResponseWriter, r *http.Request) { } } +// 删除文件/目录. func RemoveFile(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{"succ": true} defer util.RetJSON(w, r, data) @@ -189,6 +194,7 @@ func RemoveFile(w http.ResponseWriter, r *http.Request) { } } +// 文件节点,用于构造文件树. type FileNode struct { Name string `json:"name"` Path string `json:"path"` @@ -198,7 +204,7 @@ type FileNode struct { FileNodes []*FileNode `json:"children"` } -// 遍历指定的 path 构造文件树. +// 遍历指定的路径,构造文件树. func walk(path string, node *FileNode) { files := listFiles(path) diff --git a/i18n/locales.go b/i18n/locales.go index 2ee8757..bee668f 100644 --- a/i18n/locales.go +++ b/i18n/locales.go @@ -1,3 +1,4 @@ +// 国际化操作. package i18n import ( @@ -18,6 +19,7 @@ type locale struct { // 所有的 locales. var Locales = map[string]locale{} +// 加载国际化配置. func Load() { // TODO: 加载所有语言配置 bytes, _ := ioutil.ReadFile("i18n/zh_CN.json") @@ -37,12 +39,14 @@ func Load() { glog.V(5).Info("Loaded [zh_CN] locale configuration") } +// 获取请求对应的本地语言配置. func GetLangs(r *http.Request) map[string]interface{} { locale := GetLocale(r) return Locales[locale].Langs } +// 获取请求对应的 locale. func GetLocale(r *http.Request) string { // TODO: 从请求中获取 locale return "zh_CN" diff --git a/main.go b/main.go index 7c1cb30..0a9c47c 100644 --- a/main.go +++ b/main.go @@ -26,6 +26,7 @@ func init() { flag.Parse() } +// Wide 首页. func indexHandler(w http.ResponseWriter, r *http.Request) { i18n.Load() diff --git a/output/outputs.go b/output/outputs.go index f89571a..38be5aa 100644 --- a/output/outputs.go +++ b/output/outputs.go @@ -1,3 +1,4 @@ +// 构建、运行、go tool 操作. package output import ( @@ -32,6 +33,7 @@ func WSHandler(w http.ResponseWriter, r *http.Request) { glog.V(4).Infof("Open a new [Output] with session [%s], %d", sid, len(outputWS)) } +// 运行一个可执行文件. func RunHandler(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{"succ": true} defer util.RetJSON(w, r, data) @@ -105,6 +107,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) { }(rand.Int()) } +// 构建可执行文件. func BuildHandler(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{"succ": true} defer util.RetJSON(w, r, data) @@ -257,6 +260,7 @@ func BuildHandler(w http.ResponseWriter, r *http.Request) { } } +// go install. func GoInstallHandler(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{"succ": true} defer util.RetJSON(w, r, data) @@ -377,6 +381,7 @@ func GoInstallHandler(w http.ResponseWriter, r *http.Request) { } } +// go get. func GoGetHandler(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{"succ": true} defer util.RetJSON(w, r, data) diff --git a/shell/shells.go b/shell/shells.go index 33577a2..a2c3e03 100644 --- a/shell/shells.go +++ b/shell/shells.go @@ -1,11 +1,7 @@ +// Shell. package shell import ( - "github.com/b3log/wide/conf" - "github.com/b3log/wide/i18n" - "github.com/b3log/wide/user" - "github.com/golang/glog" - "github.com/gorilla/websocket" "html/template" "math/rand" "net/http" @@ -14,6 +10,12 @@ import ( "runtime" "strconv" "strings" + + "github.com/b3log/wide/conf" + "github.com/b3log/wide/i18n" + "github.com/b3log/wide/user" + "github.com/golang/glog" + "github.com/gorilla/websocket" ) var shellWS = map[string]*websocket.Conn{} diff --git a/user/sessions.go b/user/sessions.go index 8646955..7090105 100644 --- a/user/sessions.go +++ b/user/sessions.go @@ -4,4 +4,5 @@ import ( "github.com/gorilla/sessions" ) +// 用户会话. var Session = sessions.NewCookieStore([]byte("BEYOND")) diff --git a/user/users.go b/user/users.go index 8acbdae..9ce9713 100644 --- a/user/users.go +++ b/user/users.go @@ -1,12 +1,14 @@ +// 用户操作. package user import ( "encoding/json" + "net/http" + "os" + "github.com/b3log/wide/conf" "github.com/b3log/wide/util" "github.com/golang/glog" - "net/http" - "os" ) const ( @@ -15,6 +17,7 @@ const ( USER_CREATE_FAILED = "user create failed" ) +// 添加用户. func AddUser(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{"succ": true} defer util.RetJSON(w, r, data) @@ -40,6 +43,7 @@ func AddUser(w http.ResponseWriter, r *http.Request) { } } +// 初始化用户 git 仓库. func InitGitRepos(w http.ResponseWriter, r *http.Request) { data := map[string]interface{}{"succ": true} defer util.RetJSON(w, r, data) diff --git a/util/net.go b/util/net.go index a6e5b2e..713aa16 100644 --- a/util/net.go +++ b/util/net.go @@ -1,3 +1,4 @@ +// 工具. package util import ( @@ -7,9 +8,10 @@ import ( type mynet struct{} +// 网络工具. var Net = mynet{} -func (mynet) LocalIP() (string, error) { +func (*mynet) LocalIP() (string, error) { tt, err := net.Interfaces() if err != nil { diff --git a/util/ret.go b/util/ret.go index 09402cf..4c35476 100644 --- a/util/ret.go +++ b/util/ret.go @@ -2,10 +2,12 @@ package util import ( "encoding/json" - "github.com/golang/glog" "net/http" + + "github.com/golang/glog" ) +// HTTP 返回 JSON 统一处理. func RetJSON(w http.ResponseWriter, r *http.Request, res map[string]interface{}) { w.Header().Set("Content-Type", "application/json")