代码注释

This commit is contained in:
Liang Ding 2014-09-12 17:10:58 +08:00
parent fb03f8b1d9
commit 47c45f391e
10 changed files with 40 additions and 10 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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"

View File

@ -26,6 +26,7 @@ func init() {
flag.Parse()
}
// Wide 首页.
func indexHandler(w http.ResponseWriter, r *http.Request) {
i18n.Load()

View File

@ -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)

View File

@ -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{}

View File

@ -4,4 +4,5 @@ import (
"github.com/gorilla/sessions"
)
// 用户会话.
var Session = sessions.NewCookieStore([]byte("BEYOND"))

View File

@ -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)

View File

@ -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 {

View File

@ -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")