This is a simple, available short-address service.
CREATE database tinyurl;
USE tinyurl;
CREATE TABLE `tinyurl` (
`id` bigint(11) NOT NULL AUTO_INCREMENT COMMENT '自增ID',
`url` varchar(255) DEFAULT NULL COMMENT 'URL',
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=10000 DEFAULT CHARSET=utf8;
vim ./config/config.yaml
Notice Please modify the domainand database address
go run main.go web
1)generate short address
curl -XPOST http://localhost:8080/api/tinyurl -d '{"url":"http://vearne.cc/archives/39217"}'
2)watch result
curl -iv http://st.vearne.cc/2h7
curl -L http://st.vearne.cc/2h7
You can also test directly in a browser.
go build -ldflags "-s -w" -o tinyurl
./tinyurl web --config ./config/config.yaml
The project inspired by 国内有哪些靠谱的短链接服务?
