配置环境
数据库名blog 编码为utf8_general_ci
创建表
CREATE TABLE blog_tag(idint(10) unsigned NOT NULL AUTO_INCREMENT,namevarchar(100) DEFAULT '' COMMENT '标签名称',created_onint(10) unsigned DEFAULT '0' COMMENT '创建时间',created_byvarchar(100) DEFAULT '' COMMENT '创建人',modified_onint(10) unsigned DEFAULT '0' COMMENT '修改时间',modified_byvarchar(100) DEFAULT '' COMMENT '修改人',state tinyint(3) unsigned DEFAULT '1' COMMENT '状态 0为禁用、1为启用', PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='文章标签管理';
CREATE TABLE blog_article(idint(10) unsigned NOT NULL AUTO_INCREMENT,tag_idint(10) unsigned DEFAULT '0' COMMENT '标签ID',titlevarchar(100) DEFAULT '' COMMENT '文章标题',descvarchar(255) DEFAULT '' COMMENT '简述',contenttext,created_onint(11) DEFAULT NULL,created_byvarchar(100) DEFAULT '' COMMENT '创建人',modified_onint(10) unsigned DEFAULT '0' COMMENT '修改时间',modified_byvarchar(255) DEFAULT '' COMMENT '修改人',state tinyint(3) unsigned DEFAULT '1' COMMENT '状态 0为禁用1为启用', PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='文章管理';
CREATE TABLE blog_auth(idint(10) unsigned NOT NULL AUTO_INCREMENT,usernamevarchar(50) DEFAULT '' COMMENT '账号',password varchar(50) DEFAULT '' COMMENT '密码', PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; INSERT INTO blog.blog_auth (id, username, password) VALUES (null, 'test', 'test123456');
go build
用Postman
PUT:http://127.0.0.1:8000/api/v1/tags/1?name=edit1&state=0&modified_by=edit1,查看code是否返回200
DELETE:http://127.0.0.1:8000/api/v1/tags/1,查看code是否返回200
POST:http://127.0.0.1:8000/api/v1/articles?tag_id=1&title=test1&desc=test-desc&content=test-content&created_by=test-created&state=1
GET:http://127.0.0.1:8000/api/v1/articles
GET:http://127.0.0.1:8000/api/v1/articles/1
PUT:http://127.0.0.1:8000/api/v1/articles/1?tag_id=1&title=test-edit1&desc=test-desc-edit&content=test-content-edit&modified_by=test-created-edit&state=0
DELETE:http://127.0.0.1:8000/api/v1/articles/1