paintdom

package
v0.0.0-...-d6a43d8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 1, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

README

QPaint DOM API

为了简化,我们不引入多用户,只是引入多 drawing。

todo: 鉴权与安全

创建新drawing

请求包:

POST /drawings

返回包:

200 OK
Content-Type: application/json

{
    "id": <DrawingID>
}

获得drawing

请求包:

GET /drawings/<DrawingID>

返回包:

200 OK
Content-Type: application/json

{
    "shapes": [
        {
            "id": <ShapeID>
            <Shape>
        },
        ...
    ]
}

删除drawing

请求包:

DELETE /drawings/<DrawingID>

返回包:

200 OK

创建新shape

请求包:

POST /drawings/<DrawingID>/shapes
Content-Type: application/json

{
    "id": <ShapeID>,
    <Shape>
}

返回包:

200 OK

这里 Shape 是这样的:

"path": {
    "points": [
        {"x": <X>, "y": <Y>},
        ...
    ],
    "close": <Boolean>,
    "style": <ShapeStyle>
}

或者:

"line": {
    "pt1": {"x": <X>, "y": <Y>},
    "pt2": {"x": <X>, "y": <Y>},
    "style": <ShapeStyle>
}

或者:

"rect": {
    "x": <X>,
    "y": <Y>,
    "width": <Width>,
    "height": <Height>,
    "style": <ShapeStyle>
}

或者:

"ellipse": {
    "x": <X>,
    "y": <Y>,
    "radiusX": <RadiusX>,
    "radiusY": <RadiusY>,
    "style": <ShapeStyle>
}

这里 ShapeStyle 是这样的:

{
    "lineWidth": <Width>,  // 线宽
    "lineColor": <Color>,  // 线型颜色
    "fillColor": <Color>,  // 填充色
}

取得shape

请求包:

GET /drawings/<DrawingID>/shapes/<ShapeID>

返回包:

200 OK
Content-Type: application/json

{
    <Shape>
}

修改shape

请求包:

POST /drawings/<DrawingID>/shapes/<ShapeID>
Content-Type: application/json

{
    <Shape>
}

返回包:

200 OK

修改shape的顺序

请求包:

POST /drawings/<DrawingID>/shapes/<ShapeID>
Content-Type: application/json

{
    "zorder": <ZorderOperation>
}

返回包:

200 OK

这里 ZorderOperation 可能是:

  • "top": 到最顶
  • "bottom": 到最底
  • "front": 往前一层
  • "back": 往后一层

删除shape

请求包:

DELETE /drawings/<DrawingID>/shapes/<ShapeID>

返回包:

200 OK

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DBName = "qpaint"

DBName 是默认的 QPaint Database Name。

Functions

func Main

func Main()

Main 是 paintdom 程序的 main 入口。

Types

type Document

type Document struct {
	// contains filtered or unexported fields
}

Document 代表整个 QPaint DOM 的根。

func NewDocument

func NewDocument(session *mgo.Session) *Document

NewDocument 创建一个 QPaint DOM 对象。

func (*Document) Add

func (p *Document) Add(uid UserID) (drawing *Drawing, err error)

Add 创建新drawing。

func (*Document) Delete

func (p *Document) Delete(uid UserID, dgid string) (err error)

Delete 删除drawing。 我们会检查要删除的drawing是否为该uid所拥有,如果不属于删除会失败。

func (*Document) Get

func (p *Document) Get(uid UserID, dgid string) (drawing *Drawing, err error)

Get 获取drawing。 我们会检查要获取的drawing是否为该uid所拥有,如果不属于则获取会失败。

type Drawing

type Drawing struct {
	// contains filtered or unexported fields
}

Drawing 代表用户的一个drawing文档。

func (*Drawing) Add

func (p *Drawing) Add(shape Shape) (err error)

Add 添加新图形。

func (*Drawing) Delete

func (p *Drawing) Delete(id ShapeID) (err error)

Delete 删除某个图形。

func (*Drawing) Get

func (p *Drawing) Get(id ShapeID) (shape Shape, err error)

Get 取出某个图形。

func (*Drawing) GetID

func (p *Drawing) GetID() string

GetID 取得 drawing ID。

func (*Drawing) List

func (p *Drawing) List() (shapes []Shape, err error)

List 列出所有图形。

func (*Drawing) Set

func (p *Drawing) Set(id ShapeID, shape Shape) (err error)

Set 修改某个图形。

func (*Drawing) SetZorder

func (p *Drawing) SetZorder(id ShapeID, zorder string) (err error)

SetZorder 修改图形的图层。

func (*Drawing) Sync

func (p *Drawing) Sync(shapes []ShapeID, changes []Shape) (err error)

Sync 同步 drawing 的修改。

type Ellipse

type Ellipse struct {
	ShapeBase   `json:",inline" bson:",inline"`
	EllipseData `json:"ellipse" bson:"ellipse"`
}

type EllipseData

type EllipseData struct {
	X       coord      `json:"x" bson:"x"`
	Y       coord      `json:"y" bson:"y"`
	RadiusX coord      `json:"radiusX" bson:"radiusX"`
	RadiusY coord      `json:"radiusY" bson:"radiusY"`
	Style   ShapeStyle `json:"style" bson:"style"`
}

type Env

type Env struct {
	restrpc.Env
	UID UserID
}

Env 代表 RPC 请求的环境。

func (*Env) OpenEnv

func (p *Env) OpenEnv(rcvr interface{}, w *http.ResponseWriter, req *http.Request) error

OpenEnv 初始化环境。

type Line

type Line struct {
	ShapeBase `json:",inline" bson:",inline"`
	LineData  `json:"line" bson:"line"`
}

type LineData

type LineData struct {
	Pt1   Point      `json:"pt1" bson:"pt1"`
	Pt2   Point      `json:"pt2" bson:"pt2"`
	Style ShapeStyle `json:"style" bson:"style"`
}

type M

type M = bson.M

M 只是一个缩略写法。

type Path

type Path struct {
	ShapeBase `json:",inline" bson:",inline"`
	PathData  `json:"path" bson:"path"`
}

type PathData

type PathData struct {
	Points []Point    `json:"points,omitempty" bson:"points,omitempty"`
	Close  bool       `json:"close,omitempty" bson:"close,omitempty"`
	Style  ShapeStyle `json:"style" bson:"style"`
}

type Point

type Point struct {
	X coord `json:"x" bson:"x"`
	Y coord `json:"y" bson:"y"`
}

type QShape

type QShape map[string]interface{}

QShape 是 drawing 返回的 shape 实例。

func (QShape) GetID

func (shape QShape) GetID() string

GetID 取得该 shape 的 id。

type Rect

type Rect struct {
	ShapeBase `json:",inline" bson:",inline"`
	RectData  `json:"rect" bson:"rect"`
}

type RectData

type RectData struct {
	X      coord      `json:"x" bson:"x"`
	Y      coord      `json:"y" bson:"y"`
	Width  coord      `json:"width" bson:"width"`
	Height coord      `json:"height" bson:"height"`
	Style  ShapeStyle `json:"style" bson:"style"`
}

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service 提供 RESTful API 层访问接口。

func NewService

func NewService(doc *Document) (p *Service)

NewService 创建Service实例。

func (*Service) DeleteDrawing

func (p *Service) DeleteDrawing(env *Env) (err error)

DeleteDrawing 删除drawing。

func (*Service) DeleteShape

func (p *Service) DeleteShape(env *Env) (err error)

DeleteShape 删除一个shape。

func (*Service) GetDrawing

func (p *Service) GetDrawing(env *Env) (ret M, err error)

GetDrawing 取得drawing的内容。

func (*Service) GetShape

func (p *Service) GetShape(env *Env) (shape Shape, err error)

GetShape 取得一个shape的内容。

func (*Service) PostDrawingSync

func (p *Service) PostDrawingSync(ds *serviceDrawingSync, env *Env) (err error)

PostDrawingSync 同步客户端的修改。

func (*Service) PostDrawings

func (p *Service) PostDrawings(env *Env) (ret M, err error)

PostDrawings 创建新drawing。

func (*Service) PostShape

func (p *Service) PostShape(shapeOrZorder *serviceShapeOrZorder, env *Env) (err error)

PostShape 修改一个shape。

func (*Service) PostShapes

func (p *Service) PostShapes(aShape *serviceShape, env *Env) (err error)

PostShapes 创建新shape。

type Shape

type Shape interface {
	GetID() ShapeID
}

type ShapeBase

type ShapeBase struct {
	ID ShapeID `json:"id" bson:"-"`
}

func (*ShapeBase) GetID

func (p *ShapeBase) GetID() ShapeID

type ShapeID

type ShapeID = string

type ShapeStyle

type ShapeStyle struct {
	LineWidth coord  `json:"lineWidth" bson:"lineWidth"`
	LineColor string `json:"lineColor" bson:"lineColor"`
	FillColor string `json:"fillColor" bson:"fillColor"`
}

type UserID

type UserID = uint64

UserID 是用户ID,代表一个用户。

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL