gueditor go实现的百度ueditor后台接口 gueditor

dazhenghu2018-06-04 20:06:42 • 3692 次点击    
这是一个分享于 2018-06-04 20:06:42 的项目,其中的信息可能已经有所发展或是发生改变。

百度ueditor的go语言后台服务程序

说明:

百度提供的富文本框插件ueditor,因官方没有提供go版本后台,此项目旨在提供一个go的后台接口

因个人精力有限,代码中还有一些不足之处,希望使用该库的同学能够发扬开源精神一起完善该库

示例、:

基于gin框架的样例(https://github.com/dazhenghu/ginCms 中的admin模块)

package controller

import (
    "github.com/dazhenghu/ginApp/controller"
    "github.com/gin-gonic/gin"
    "github.com/dazhenghu/gueditor"
    "github.com/dazhenghu/util/fileutil"
    "net/http"
    "path/filepath"
    "syscall"
)

type ueditorController struct {
    controller.Controller
}

var ueditorInstance *ueditorController
var uedService *gueditor.Service

func init() {
    ueditorInstance = &ueditorController{}
    ueditorInstance.Init(ueditorInstance)

    syscall.Umask(0)
    rootPath, _    := fileutil.GetCurrentDirectory()
    configFilePath := filepath.Join(rootPath, "config/ueditor.json") // 设置自定义配置文件路径

    rootPath      = filepath.Join(rootPath, "../") // 设置项目根目录
    uedService, _ = gueditor.NewService(nil, nil, rootPath, configFilePath)

    ueditorInstance.PostAndGet("/ueditor", ueditorInstance.index)
}

func (ued *ueditorController) index(context *gin.Context) {
    action := context.Query("action")

    switch action {
    case "config":
        // config接口
        ued.config(context)
    case "uploadimage":
        // 上传图片
        ued.uploadImage(context)
    case "uploadscrawl":
        // 上传涂鸦
        ued.uploadScrawl(context)
    case "uploadvideo":
        // 上传视频
        ued.uploadVideo(context)
    case "uploadfile":
        // 上传附件
        ued.uploadfile(context)
    case "listfile":
        // 查询上传的文件列表
        ued.listFile(context)
    case "listimage":
        // 查询上传的图片列表
        ued.listImage(context)
    }

}

func (ued *ueditorController) config(context *gin.Context) {
    cnf := uedService.Config()
    context.JSON(http.StatusOK, cnf)
}

func (ued *ueditorController) uploadImage(context *gin.Context) {
    res, _ := uedService.Uploadimage(context.Request)
    context.JSON(http.StatusOK, res)
}

func (ued *ueditorController) uploadScrawl(context *gin.Context)  {
    res, _ := uedService.UploadScrawl(context.Request)
    context.JSON(http.StatusOK, res)
}

func (ued *ueditorController) uploadVideo(context *gin.Context)  {
    res, _ := uedService.UploadVideo(context.Request)
    context.JSON(http.StatusOK, res)
}

func (ued *ueditorController) uploadfile(context *gin.Context)  {
    res, _ := uedService.UploadFile(context.Request)
    context.JSON(http.StatusOK, res)
}

func (ued *ueditorController) listFile(context *gin.Context) {
    listFileItem := &gueditor.ListFileItem{}
    uedService.Listfile(listFileItem, 0, 10)
    context.JSON(http.StatusOK, listFileItem)
}

func (ued *ueditorController) listImage(context *gin.Context)  {
    listFileItem := &gueditor.ListFileItem{}
    uedService.ListImage(listFileItem, 0, 10)
    context.JSON(http.StatusOK, listFileItem)
}

go语言ueditor后台接口Read More

Latest commit to the master branch on 9-28-2018
Download as zip
授权协议:
开发语言:
golang 查看源码»
3692 次点击  
加入收藏 微博
添加一条新回复 (您需要 登录 后才能回复 没有账号 ?)
  • 请尽量让自己的回复能够对别人有帮助
  • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`
  • 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
  • 图片支持拖拽、截图粘贴等方式上传