• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang util.RetJSON函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/b3log/wide/util.RetJSON函数的典型用法代码示例。如果您正苦于以下问题:Golang RetJSON函数的具体用法?Golang RetJSON怎么用?Golang RetJSON使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了RetJSON函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: DecompressHandler

// DecompressHandler handles request of decompressing zip/tar.gz.
func DecompressHandler(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
	}

	path := args["path"].(string)
	//	base := filepath.Base(path)
	dir := filepath.Dir(path)

	if !util.File.IsExist(path) {
		data["succ"] = false
		data["msg"] = "Can't find file [" + path + "] to descompress"

		return
	}

	err := util.Zip.Unzip(path, dir)
	if nil != err {
		logger.Error(err)
		data["succ"] = false

		return
	}

}
开发者ID:EricRobert,项目名称:wide,代码行数:33,代码来源:decompress.go


示例2: setCursorHandler

func setCursorHandler(w http.ResponseWriter, r *http.Request) {
	data := map[string]interface{}{"succ": true}
	defer util.RetJSON(w, r, data)

	httpSession, _ := httpSessionStore.Get(r, "coditor-session")
	userSession := httpSession.Values[user_session]
	if nil == userSession {
		data["succ"] = false
		data["msg"] = "permission denied"
		return
	}

	var args map[string]interface{}
	if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
		logger.Error(err)
		data["succ"] = false
		return
	}

	sid := args["sid"].(string)
	docName := args["docName"].(string)
	offset := args["offset"].(float64)
	color := args["color"].(string)
	user := userSession.(*User)

	md5Email := toMd5(user.Email)

	cursor := &Cursor{Sid: sid, Offset: int(offset), Username: user.Username, Color: color, Email: user.Email, Md5Email: md5Email}

	docName = filepath.Clean(docName)

	doc := documentHolder.getDoc(docName)
	doc.addCursor(cursor)
}
开发者ID:marswang,项目名称:coditorx,代码行数:34,代码来源:cursor.go


示例3: LoginHandler

// LoginHandler handles request of user login.
func LoginHandler(w http.ResponseWriter, r *http.Request) {
	if "GET" == r.Method {
		// show the login page

		model := map[string]interface{}{"conf": conf.Wide, "i18n": i18n.GetAll(conf.Wide.Locale),
			"locale": conf.Wide.Locale, "ver": conf.WideVersion, "year": time.Now().Year()}

		t, err := template.ParseFiles("views/login.html")

		if nil != err {
			logger.Error(err)
			http.Error(w, err.Error(), 500)

			return
		}

		t.Execute(w, model)

		return
	}

	// non-GET request as login request

	succ := true
	data := map[string]interface{}{"succ": &succ}
	defer util.RetJSON(w, r, data)

	args := struct {
		Username string
		Password string
	}{}

	args.Username = r.FormValue("username")
	args.Password = r.FormValue("password")

	succ = false
	for _, user := range conf.Users {
		if user.Name == args.Username && user.Password == conf.Salt(args.Password, user.Salt) {
			succ = true

			break
		}
	}

	if !succ {
		return
	}

	// create a HTTP session
	httpSession, _ := HTTPSession.Get(r, "wide-session")
	httpSession.Values["username"] = args.Username
	httpSession.Values["id"] = strconv.Itoa(rand.Int())
	httpSession.Options.MaxAge = conf.Wide.HTTPSessionMaxAge
	if "" != conf.Wide.Context {
		httpSession.Options.Path = conf.Wide.Context
	}
	httpSession.Save(r, w)

	logger.Debugf("Created a HTTP session [%s] for user [%s]", httpSession.Values["id"].(string), args.Username)
}
开发者ID:EricRobert,项目名称:wide,代码行数:61,代码来源:users.go


示例4: listCursorsHandler

func listCursorsHandler(w http.ResponseWriter, r *http.Request) {
	data := map[string]interface{}{"succ": true}
	defer util.RetJSON(w, r, data)

	httpSession, _ := httpSessionStore.Get(r, "coditor-session")
	userSession := httpSession.Values[user_session]
	if nil == userSession {
		data["succ"] = false
		data["msg"] = "permission denied"
		return
	}

	var args map[string]interface{}
	if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
		logger.Error(err)
		data["succ"] = false
		return
	}

	docName := args["docName"].(string)
	doc := documentHolder.getDoc(docName)
	if doc == nil {
		data["succ"] = false
		data["msg"] = "Can not find the document."
		return
	}

	cursors := doc.getCursors()
	data["cursors"] = cursors
}
开发者ID:marswang,项目名称:coditorx,代码行数:30,代码来源:cursor.go


示例5: fetchDocHandler

func fetchDocHandler(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
		data["msg"] = "args decode error!"
		return
	}

	fileArgs := args["file"].(map[string]interface{})
	if fileArgs == nil {
		data["succ"] = false
		data["msg"] = "args error!"
		return
	}

	fileName := fileArgs["name"].(string)
	fileVersion := DocVersion(uint32(fileArgs["version"].(float64)))

	httpSession, _ := httpSessionStore.Get(r, "coditor-session")
	userSession := httpSession.Values[user_session]
	if nil == userSession {
		data["succ"] = false
		data["msg"] = "permission denied"
		return
	}

	user := userSession.(*User)
	// FIXME: doc permission check

	docName := filepath.Clean(fileName)

	doc := documentHolder.getDoc(docName)
	if doc == nil {
		data["succ"] = false
		data["msg"] = "document not exist!"
		return
	}

	patchss, err := doc.tail(fileVersion, user.Username)
	if err != nil {
		data["succ"] = false
		data["msg"] = err.Error()
		return
	}

	data["patchss"] = patchss
	version, err := doc.getVersion(user.Username)
	if err != nil {
		data["succ"] = false
		data["msg"] = err.Error()
		return
	}
	data["version"] = version
}
开发者ID:marswang,项目名称:coditorx,代码行数:59,代码来源:version.go


示例6: GoFmtHandler

func GoFmtHandler(w http.ResponseWriter, r *http.Request) {
	data := map[string]interface{}{"succ": true}
	defer util.RetJSON(w, r, data)

	decoder := json.NewDecoder(r.Body)

	var args map[string]interface{}

	if err := decoder.Decode(&args); err != nil {
		glog.Error(err)
		data["succ"] = false

		return
	}

	filePath := args["file"].(string)

	fout, err := os.Create(filePath)

	if nil != err {
		glog.Error(err)
		data["succ"] = false

		return
	}

	code := args["code"].(string)

	fout.WriteString(code)
	if err := fout.Close(); nil != err {
		glog.Error(err)
		data["succ"] = false

		return
	}

	argv := []string{filePath}
	cmd := exec.Command("gofmt", argv...)

	bytes, _ := cmd.Output()
	output := string(bytes)
	if "" == output {
		data["succ"] = false

		return
	}

	code = string(output)
	data["code"] = code

	fout, err = os.Create(filePath)
	fout.WriteString(code)
	if err := fout.Close(); nil != err {
		glog.Error(err)
		data["succ"] = false

		return
	}
}
开发者ID:aprilsky,项目名称:wide,代码行数:59,代码来源:formatter.go


示例7: LogoutHandler

// LogoutHandler handles request of user logout (exit).
func LogoutHandler(w http.ResponseWriter, r *http.Request) {
	data := map[string]interface{}{"succ": true}
	defer util.RetJSON(w, r, data)

	httpSession, _ := HTTPSession.Get(r, "wide-session")

	httpSession.Options.MaxAge = -1
	httpSession.Save(r, w)
}
开发者ID:EricRobert,项目名称:wide,代码行数:10,代码来源:users.go


示例8: getHeadDocHandler

func getHeadDocHandler(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
		data["msg"] = "args decode error!"
		return
	}

	var fileName string
	fileNameArg := args["fileName"]
	if fileNameArg == nil {
		data["succ"] = false
		data["msg"] = "fileName can not bu nil."
		return
	}

	fileName = fileNameArg.(string)

	httpSession, _ := httpSessionStore.Get(r, "coditor-session")
	userSession := httpSession.Values[user_session]
	if nil == userSession {
		data["succ"] = false
		data["msg"] = "permission denied"
		return
	}

	user := userSession.(*User)
	// FIXME: doc permission check

	docName := filepath.Clean(fileName)

	doc := documentHolder.getDoc(docName)
	if doc == nil {
		data["succ"] = false
		data["msg"] = "document not exist!"
		return
	}

	output := make(map[string]interface{})
	content, err := doc.getContents(user.Username)
	if err != nil {
		data["succ"] = false
		data["msg"] = err.Error()
		return
	}

	output["content"] = content
	version, _ := doc.getVersion(user.Username)
	output["version"] = version

	data["output"] = output
}
开发者ID:marswang,项目名称:coditorx,代码行数:57,代码来源:version.go


示例9: UploadHandler

// UploadHandler handles request of file upload.
func UploadHandler(w http.ResponseWriter, r *http.Request) {
	data := map[string]interface{}{"succ": true}
	defer util.RetJSON(w, r, data)

	q := r.URL.Query()
	dir := q["path"][0]

	data["files"] = handleUploads(r, dir)
}
开发者ID:EricRobert,项目名称:wide,代码行数:10,代码来源:importer.go


示例10: HTMLFmtHandler

func HTMLFmtHandler(w http.ResponseWriter, r *http.Request) {
	data := map[string]interface{}{"succ": true}
	defer util.RetJSON(w, r, data)

	decoder := json.NewDecoder(r.Body)

	var args map[string]interface{}

	if err := decoder.Decode(&args); err != nil {
		glog.Error(err)
		data["succ"] = false

		return
	}

	filePath := args["file"].(string)

	fout, err := os.Create(filePath)

	if nil != err {
		glog.Error(err)
		data["succ"] = false

		return
	}

	code := args["code"].(string)

	fout.WriteString(code)
	if err := fout.Close(); nil != err {
		glog.Error(err)
		data["succ"] = false

		return
	}

	output := gohtml.Format(code)
	if "" == output {
		data["succ"] = false

		return
	}

	code = string(output)
	data["code"] = code

	fout, err = os.Create(filePath)
	fout.WriteString(code)
	if err := fout.Close(); nil != err {
		glog.Error(err)
		data["succ"] = false

		return
	}
}
开发者ID:aprilsky,项目名称:wide,代码行数:55,代码来源:formatter.go


示例11: SaveFileHandler

// SaveFileHandler handles request of saving file.
func SaveFileHandler(w http.ResponseWriter, r *http.Request) {
	httpSession, _ := session.HTTPSession.Get(r, "wide-session")
	if httpSession.IsNew {
		http.Error(w, "Forbidden", http.StatusForbidden)

		return
	}
	username := httpSession.Values["username"].(string)

	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
	}

	filePath := args["file"].(string)
	sid := args["sid"].(string)

	if util.Go.IsAPI(filePath) || !session.CanAccess(username, filePath) {
		http.Error(w, "Forbidden", http.StatusForbidden)

		return
	}

	fout, err := os.Create(filePath)

	if nil != err {
		logger.Error(err)
		data["succ"] = false

		return
	}

	code := args["code"].(string)

	fout.WriteString(code)

	if err := fout.Close(); nil != err {
		logger.Error(err)
		data["succ"] = false

		wSession := session.WideSessions.Get(sid)
		wSession.EventQueue.Queue <- &event.Event{Code: event.EvtCodeServerInternalError, Sid: sid,
			Data: "can't save file " + filePath}

		return
	}
}
开发者ID:npchp110,项目名称:wide,代码行数:55,代码来源:files.go


示例12: FindHandler

// FindHandler handles request of find files under the specified directory with the specified filename pattern.
func FindHandler(w http.ResponseWriter, r *http.Request) {
	httpSession, _ := session.HTTPSession.Get(r, "wide-session")
	if httpSession.IsNew {
		http.Error(w, "Forbidden", http.StatusForbidden)

		return
	}
	username := httpSession.Values["username"].(string)

	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
	}

	path := args["path"].(string) // path of selected file in file tree
	if !util.Go.IsAPI(path) && !session.CanAccess(username, path) {
		http.Error(w, "Forbidden", http.StatusForbidden)

		return
	}

	name := args["name"].(string)

	userWorkspace := conf.GetUserWorkspace(username)
	workspaces := filepath.SplitList(userWorkspace)

	if "" != path && !util.File.IsDir(path) {
		path = filepath.Dir(path)
	}

	founds := foundPaths{}

	for _, workspace := range workspaces {
		rs := find(workspace+conf.PathSeparator+"src", name, []*string{})

		for _, r := range rs {
			substr := util.Str.LCS(path, *r)

			founds = append(founds, &foundPath{Path: *r, score: len(substr)})
		}
	}

	sort.Sort(founds)

	data["founds"] = founds
}
开发者ID:npchp110,项目名称:wide,代码行数:53,代码来源:files.go


示例13: InitGitRepos

func InitGitRepos(w http.ResponseWriter, r *http.Request) {
	data := map[string]interface{}{"succ": true}
	defer util.RetJSON(w, r, data)

	session, _ := Session.Get(r, "wide-session")

	username := session.Values["username"].(string)
	userRepos := conf.Wide.UserWorkspaces + string(os.PathSeparator) + username + string(os.PathSeparator) + "src"

	// TODO: git clone

	glog.Infof("Git Cloned from [%s] to [%s]", conf.Wide.Workspace+string(os.PathSeparator)+"src", userRepos)
}
开发者ID:aprilsky,项目名称:wide,代码行数:13,代码来源:users.go


示例14: RenameFileHandler

// RenameFileHandler handles request of renaming file or directory.
func RenameFileHandler(w http.ResponseWriter, r *http.Request) {
	httpSession, _ := session.HTTPSession.Get(r, "wide-session")
	if httpSession.IsNew {
		http.Error(w, "Forbidden", http.StatusForbidden)

		return
	}
	username := httpSession.Values["username"].(string)

	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
	}

	oldPath := args["oldPath"].(string)
	if util.Go.IsAPI(oldPath) ||
		!session.CanAccess(username, oldPath) {
		http.Error(w, "Forbidden", http.StatusForbidden)

		return
	}

	newPath := args["newPath"].(string)
	if util.Go.IsAPI(newPath) || !session.CanAccess(username, newPath) {
		http.Error(w, "Forbidden", http.StatusForbidden)

		return
	}

	sid := args["sid"].(string)

	wSession := session.WideSessions.Get(sid)

	if !renameFile(oldPath, newPath) {
		data["succ"] = false

		wSession.EventQueue.Queue <- &event.Event{Code: event.EvtCodeServerInternalError, Sid: sid,
			Data: "can't rename file " + oldPath}

		return
	}

	logger.Debugf("Renamed a file [%s] to [%s] by user [%s]", oldPath, newPath, wSession.Username)
}
开发者ID:npchp110,项目名称:wide,代码行数:52,代码来源:files.go


示例15: fileTreeHandler

func fileTreeHandler(w http.ResponseWriter, r *http.Request) {
	// XXX: it's a list now, not a tree

	data := map[string]interface{}{"succ": true}
	defer util.RetJSON(w, r, data)

	httpSession, _ := httpSessionStore.Get(r, "coditor-session")
	userSession := httpSession.Values[user_session]
	if nil == userSession {
		data["succ"] = false
		data["msg"] = "permission denied"
		return
	}

	user := userSession.(*User)
	names := listFiles(user.getWorkspace())
	files := []*file{}
	for i, fname := range names {
		t := filepath.Ext(fname)
		if strings.HasPrefix(t, ".") {
			t = t[1:]
		}

		isShare := false
		var dmd *DocumentMetaData
		var err error
		docName := filepath.Join("workspaces", user.Username, "workspace", fname)
		doc := documentHolder.getDoc(docName)
		if doc != nil {
			dmd = doc.metaData
		} else {
			fileRelPath := filepath.Join(user.getWorkspace(), fname)
			dmd, err = newDocumentMetaData(fileRelPath)

		}
		if err != nil {
			// TODO how to handler this err?
			logger.Error(err)
		} else {
			if dmd.IsPublic == 1 || len(dmd.Editors) > 0 || len(dmd.Viewers) > 0 {
				isShare = true
			}
		}

		f := &file{ID: strconv.Itoa(i), IsShare: isShare, Name: fname, Type: t}

		files = append(files, f)
	}

	data["files"] = files
}
开发者ID:marswang,项目名称:coditorx,代码行数:51,代码来源:file.go


示例16: NewFileHandler

// NewFileHandler handles request of creating file or directory.
func NewFileHandler(w http.ResponseWriter, r *http.Request) {
	httpSession, _ := session.HTTPSession.Get(r, "wide-session")
	if httpSession.IsNew {
		http.Error(w, "Forbidden", http.StatusForbidden)

		return
	}
	username := httpSession.Values["username"].(string)

	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
	}

	path := args["path"].(string)

	if util.Go.IsAPI(path) || !session.CanAccess(username, path) {
		http.Error(w, "Forbidden", http.StatusForbidden)

		return
	}

	fileType := args["fileType"].(string)
	sid := args["sid"].(string)

	wSession := session.WideSessions.Get(sid)

	if !createFile(path, fileType) {
		data["succ"] = false

		wSession.EventQueue.Queue <- &event.Event{Code: event.EvtCodeServerInternalError, Sid: sid,
			Data: "can't create file " + path}

		return
	}

	if "f" == fileType {
		logger.Debugf("Created a file [%s] by user [%s]", path, wSession.Username)
	} else {
		logger.Debugf("Created a dir [%s] by user [%s]", path, wSession.Username)
	}

}
开发者ID:npchp110,项目名称:wide,代码行数:51,代码来源:files.go


示例17: getShareInfoHandler

func getShareInfoHandler(w http.ResponseWriter, r *http.Request) {
	data := map[string]interface{}{"succ": true}
	defer util.RetJSON(w, r, data)

	httpSession, _ := httpSessionStore.Get(r, "coditor-session")
	userSession := httpSession.Values[user_session]
	if nil == userSession {
		data["succ"] = false
		data["msg"] = "permission denied"
		return
	}

	var args map[string]interface{}
	if err := json.NewDecoder(r.Body).Decode(&args); err != nil {
		logger.Error(err)
		data["succ"] = false
		data["msg"] = "args decode error!"
		return
	}

	docName := args["docName"]
	if docName == nil || len(docName.(string)) == 0 {
		data["succ"] = false
		data["msg"] = "docName can not be null!"
		return
	}
	filePath := docName.(string)

	// check file first
	metaDataFileName := filePath + ".json.coditor"
	absMetaDataFileName := filepath.Clean(metaDataFileName)
	file, err := os.Open(absMetaDataFileName)
	if err != nil {
		logger.Error(err)
		data["succ"] = false
		data["msg"] = err.Error()
		return
	}
	file.Close()

	dmd, err := newDocumentMetaData(filePath)
	if err != nil {
		logger.Error(err)
		data["succ"] = false
		data["msg"] = err.Error()
		return
	}

	data["shareInfo"] = dmd
}
开发者ID:marswang,项目名称:coditorx,代码行数:50,代码来源:share.go


示例18: CreateZipHandler

// CreateZipHandler handles request of creating zip.
func CreateZipHandler(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
	}

	path := args["path"].(string)
	var name string

	base := filepath.Base(path)

	if nil != args["name"] {
		name = args["name"].(string)
	} else {
		name = base
	}

	dir := filepath.Dir(path)

	if !util.File.IsExist(path) {
		data["succ"] = false
		data["msg"] = "Can't find file [" + path + "]"

		return
	}

	zipPath := filepath.Join(dir, name)
	zipFile, err := util.Zip.Create(zipPath + ".zip")
	if nil != err {
		logger.Error(err)
		data["succ"] = false

		return
	}
	defer zipFile.Close()

	if util.File.IsDir(path) {
		zipFile.AddDirectory(base, path)
	} else {
		zipFile.AddEntry(base, path)
	}

	data["path"] = zipPath
}
开发者ID:rdterner,项目名称:wide,代码行数:51,代码来源:exporter.go


示例19: SearchTextHandler

// SearchTextHandler handles request of searching files under the specified directory with the specified keyword.
func SearchTextHandler(w http.ResponseWriter, r *http.Request) {
	httpSession, _ := session.HTTPSession.Get(r, "wide-session")
	if httpSession.IsNew {
		http.Error(w, "Forbidden", http.StatusForbidden)

		return
	}

	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
	}

	sid := args["sid"].(string)
	wSession := session.WideSessions.Get(sid)
	if nil == wSession {
		data["succ"] = false

		return
	}

	// XXX: just one directory

	dir := args["dir"].(string)
	if "" == dir {
		userWorkspace := conf.GetUserWorkspace(wSession.Username)
		workspaces := filepath.SplitList(userWorkspace)
		dir = workspaces[0]
	}

	extension := args["extension"].(string)
	text := args["text"].(string)

	founds := []*Snippet{}
	if util.File.IsDir(dir) {
		founds = search(dir, extension, text, []*Snippet{})
	} else {
		founds = searchInFile(dir, text)
	}

	data["founds"] = founds
}
开发者ID:npchp110,项目名称:wide,代码行数:50,代码来源:files.go


示例20: GetFile

func GetFile(w http.ResponseWriter, r *http.Request) {
	data := map[string]interface{}{"succ": true}
	defer util.RetJSON(w, r, data)

	decoder := json.NewDecoder(r.Body)

	var args map[string]interface{}

	if err := decoder.Decode(&args); err != nil {
		glog.Error(err)
		data["succ"] = false

		return
	}

	path := args["path"].(string)
	buf, _ := ioutil.ReadFile(path)

	extension := filepath.Ext(path)

	// 通过文件扩展名判断是否是图片文件(图片在浏览器里新建 tab 打开)
	if isImg(extension) {
		data["mode"] = "img"

		path2 := strings.Replace(path, "\\", "/", -1)
		idx := strings.Index(path2, "/data/user_workspaces")
		data["path"] = path2[idx:]

		return
	}

	isBinary := false
	// 判断是否是其他二进制文件
	for _, b := range buf {
		if 0 == b { // 包含 0 字节就认为是二进制文件
			isBinary = true
		}
	}

	if isBinary {
		// 是二进制文件的话前端编辑器不打开
		data["succ"] = false
		data["msg"] = "Can't open a binary file :("
	} else {
		data["content"] = string(buf)
		data["mode"] = getEditorMode(extension)
	}
}
开发者ID:aprilsky,项目名称:wide,代码行数:48,代码来源:files.go



注:本文中的github.com/b3log/wide/util.RetJSON函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang util.RetResult函数代码示例发布时间:2022-05-24
下一篇:
Golang util.Recover函数代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap