代码注释
This commit is contained in:
parent
fb03f8b1d9
commit
47c45f391e
|
@ -1,3 +1,4 @@
|
||||||
|
// 编辑器操作.
|
||||||
package editor
|
package editor
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -149,6 +150,7 @@ func AutocompleteHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
w.Write(output)
|
w.Write(output)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 查找声明.
|
||||||
func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
|
func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
data := map[string]interface{}{"succ": true}
|
||||||
defer util.RetJSON(w, r, data)
|
defer util.RetJSON(w, r, data)
|
||||||
|
@ -230,6 +232,7 @@ func FindDeclarationHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data["cursorCh"] = cursorCh
|
data["cursorCh"] = cursorCh
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 查找使用.
|
||||||
func FindUsagesHandler(w http.ResponseWriter, r *http.Request) {
|
func FindUsagesHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
data := map[string]interface{}{"succ": true}
|
||||||
defer util.RetJSON(w, r, data)
|
defer util.RetJSON(w, r, data)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// 文件树操作.
|
||||||
package file
|
package file
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -57,6 +58,7 @@ func GetFiles(w http.ResponseWriter, r *http.Request) {
|
||||||
data["root"] = root
|
data["root"] = root
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 编辑器打开一个文件.
|
||||||
func GetFile(w http.ResponseWriter, r *http.Request) {
|
func GetFile(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
data := map[string]interface{}{"succ": true}
|
||||||
defer util.RetJSON(w, r, data)
|
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) {
|
func SaveFile(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
data := map[string]interface{}{"succ": true}
|
||||||
defer util.RetJSON(w, r, data)
|
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) {
|
func NewFile(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
data := map[string]interface{}{"succ": true}
|
||||||
defer util.RetJSON(w, r, data)
|
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) {
|
func RemoveFile(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
data := map[string]interface{}{"succ": true}
|
||||||
defer util.RetJSON(w, r, data)
|
defer util.RetJSON(w, r, data)
|
||||||
|
@ -189,6 +194,7 @@ func RemoveFile(w http.ResponseWriter, r *http.Request) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 文件节点,用于构造文件树.
|
||||||
type FileNode struct {
|
type FileNode struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Path string `json:"path"`
|
Path string `json:"path"`
|
||||||
|
@ -198,7 +204,7 @@ type FileNode struct {
|
||||||
FileNodes []*FileNode `json:"children"`
|
FileNodes []*FileNode `json:"children"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// 遍历指定的 path 构造文件树.
|
// 遍历指定的路径,构造文件树.
|
||||||
func walk(path string, node *FileNode) {
|
func walk(path string, node *FileNode) {
|
||||||
files := listFiles(path)
|
files := listFiles(path)
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// 国际化操作.
|
||||||
package i18n
|
package i18n
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -18,6 +19,7 @@ type locale struct {
|
||||||
// 所有的 locales.
|
// 所有的 locales.
|
||||||
var Locales = map[string]locale{}
|
var Locales = map[string]locale{}
|
||||||
|
|
||||||
|
// 加载国际化配置.
|
||||||
func Load() {
|
func Load() {
|
||||||
// TODO: 加载所有语言配置
|
// TODO: 加载所有语言配置
|
||||||
bytes, _ := ioutil.ReadFile("i18n/zh_CN.json")
|
bytes, _ := ioutil.ReadFile("i18n/zh_CN.json")
|
||||||
|
@ -37,12 +39,14 @@ func Load() {
|
||||||
glog.V(5).Info("Loaded [zh_CN] locale configuration")
|
glog.V(5).Info("Loaded [zh_CN] locale configuration")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取请求对应的本地语言配置.
|
||||||
func GetLangs(r *http.Request) map[string]interface{} {
|
func GetLangs(r *http.Request) map[string]interface{} {
|
||||||
locale := GetLocale(r)
|
locale := GetLocale(r)
|
||||||
|
|
||||||
return Locales[locale].Langs
|
return Locales[locale].Langs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 获取请求对应的 locale.
|
||||||
func GetLocale(r *http.Request) string {
|
func GetLocale(r *http.Request) string {
|
||||||
// TODO: 从请求中获取 locale
|
// TODO: 从请求中获取 locale
|
||||||
return "zh_CN"
|
return "zh_CN"
|
||||||
|
|
1
main.go
1
main.go
|
@ -26,6 +26,7 @@ func init() {
|
||||||
flag.Parse()
|
flag.Parse()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Wide 首页.
|
||||||
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
func indexHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
i18n.Load()
|
i18n.Load()
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// 构建、运行、go tool 操作.
|
||||||
package output
|
package output
|
||||||
|
|
||||||
import (
|
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))
|
glog.V(4).Infof("Open a new [Output] with session [%s], %d", sid, len(outputWS))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 运行一个可执行文件.
|
||||||
func RunHandler(w http.ResponseWriter, r *http.Request) {
|
func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
data := map[string]interface{}{"succ": true}
|
||||||
defer util.RetJSON(w, r, data)
|
defer util.RetJSON(w, r, data)
|
||||||
|
@ -105,6 +107,7 @@ func RunHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
}(rand.Int())
|
}(rand.Int())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 构建可执行文件.
|
||||||
func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
func BuildHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
data := map[string]interface{}{"succ": true}
|
||||||
defer util.RetJSON(w, r, data)
|
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) {
|
func GoInstallHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
data := map[string]interface{}{"succ": true}
|
||||||
defer util.RetJSON(w, r, data)
|
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) {
|
func GoGetHandler(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
data := map[string]interface{}{"succ": true}
|
||||||
defer util.RetJSON(w, r, data)
|
defer util.RetJSON(w, r, data)
|
||||||
|
|
|
@ -1,11 +1,7 @@
|
||||||
|
// Shell.
|
||||||
package shell
|
package shell
|
||||||
|
|
||||||
import (
|
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"
|
"html/template"
|
||||||
"math/rand"
|
"math/rand"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
@ -14,6 +10,12 @@ import (
|
||||||
"runtime"
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"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{}
|
var shellWS = map[string]*websocket.Conn{}
|
||||||
|
|
|
@ -4,4 +4,5 @@ import (
|
||||||
"github.com/gorilla/sessions"
|
"github.com/gorilla/sessions"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 用户会话.
|
||||||
var Session = sessions.NewCookieStore([]byte("BEYOND"))
|
var Session = sessions.NewCookieStore([]byte("BEYOND"))
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
|
// 用户操作.
|
||||||
package user
|
package user
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/b3log/wide/conf"
|
"github.com/b3log/wide/conf"
|
||||||
"github.com/b3log/wide/util"
|
"github.com/b3log/wide/util"
|
||||||
"github.com/golang/glog"
|
"github.com/golang/glog"
|
||||||
"net/http"
|
|
||||||
"os"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -15,6 +17,7 @@ const (
|
||||||
USER_CREATE_FAILED = "user create failed"
|
USER_CREATE_FAILED = "user create failed"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// 添加用户.
|
||||||
func AddUser(w http.ResponseWriter, r *http.Request) {
|
func AddUser(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
data := map[string]interface{}{"succ": true}
|
||||||
defer util.RetJSON(w, r, data)
|
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) {
|
func InitGitRepos(w http.ResponseWriter, r *http.Request) {
|
||||||
data := map[string]interface{}{"succ": true}
|
data := map[string]interface{}{"succ": true}
|
||||||
defer util.RetJSON(w, r, data)
|
defer util.RetJSON(w, r, data)
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
// 工具.
|
||||||
package util
|
package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
@ -7,9 +8,10 @@ import (
|
||||||
|
|
||||||
type mynet struct{}
|
type mynet struct{}
|
||||||
|
|
||||||
|
// 网络工具.
|
||||||
var Net = mynet{}
|
var Net = mynet{}
|
||||||
|
|
||||||
func (mynet) LocalIP() (string, error) {
|
func (*mynet) LocalIP() (string, error) {
|
||||||
tt, err := net.Interfaces()
|
tt, err := net.Interfaces()
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -2,10 +2,12 @@ package util
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"github.com/golang/glog"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/golang/glog"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// HTTP 返回 JSON 统一处理.
|
||||||
func RetJSON(w http.ResponseWriter, r *http.Request, res map[string]interface{}) {
|
func RetJSON(w http.ResponseWriter, r *http.Request, res map[string]interface{}) {
|
||||||
w.Header().Set("Content-Type", "application/json")
|
w.Header().Set("Content-Type", "application/json")
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue