Giter Site home page Giter Site logo

short_url's Introduction

short_url

短链接生成服务

特性

  • 单点服务
  • 主从服务
  • rpc交互
  • chan异步写入
  • 服务内使用内存缓存
  • 支持直接引入包使用
  • 支持部署http服务使用

使用

单点服务

启动服务

go build main.go && main

长链生成短链

curl --location --request POST '127.0.0.1:8080/put' \
--form 'url=https://www.kxjun.top/'

# http://www.frommaster.com 长链生成的短链为 1
# Successed shortURL(short: long) is 0: https://www.kxjun.top

使用短链获取长链

curl --location --request POST '127.0.0.1:8080/get' \
--form 'key=0'

# Successed shortURL(short: long) is 0: https://www.kxjun.top

使用短链访问

使用浏览器访问:127.0.0.1:8080/0 会重定向到 https://www.kxjun.top

主从服务

启动服务

go build main.go

# 启动主服务
main -port=:8080 -rpc=true 

# 启动从服务1
main -master=127.0.0.1:8080 -port=:8081

# 启动从服务2
main -master=127.0.0.1:8080 -port=:8082

长链生成短链

curl --location --request POST '127.0.0.1:8081/put' \
--form 'url=https://www.slave1.top/'

curl --location --request POST '127.0.0.1:8082/put' \
--form 'url=https://www.slave2.top/'

curl --location --request POST '127.0.0.1:8080/put' \
--form 'url=https://www.master.top/'

# Successed shortURL(short: long) is 1: https://www.slave1.top/
# Successed shortURL(short: long) is 2: https://www.slave2.top/
# Successed shortURL(short: long) is 3: https://www.master.top/

使用短链获取长链

# 主服务:127.0.0.1:8080
# 从服务1:127.0.0.1:8081
# 从服务2:127.0.0.1:8082
curl --location --request POST '127.0.0.1:8082/get' \
--form 'key=0'

# Successed shortURL(short: long) is 0: https://www.kxjun.top

使用短链访问

使用浏览器访问:

主:127.0.0.1:8080/0

从:127.0.0.1:8081/0 or 127.0.0.1:8082/0

会重定向到 https://www.kxjun.top

参数

$ main --help

Usage of main:
    -file string
data store filename (default "store.json")
    -host string
hostname (default "127.0.0.1")
    -master string
rpc master address
    -port string
http listen port (default ":8080")
    -rpc
enable rpc service

short_url's People

Contributors

frankxjkuang avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.