shortify:一个用 Go 编写的简单的 URL 缩短器应用程序

  • h0_825296
    了解作者
  • 16.9KB
    文件大小
  • zip
    文件格式
  • 0
    收藏次数
  • VIP专享
    资源类型
  • 0
    下载次数
  • 2022-06-05 06:18
    上传日期
缩短 一个用 Go 编写的简单的 URL 缩短器应用程序。 入门 前往并下载shortify可执行文件。 从源头构建 git clone https://github.com/shortify/shortify.git script/build 配置 为了运行 shortify,您需要创建一个名为shortify.gcfg的配置文件。 这个文件必须放在可执行文件旁边。 以下是典型配置文件的示例: [database] provider = mysql dataSource = tcp://localhost:3306*mydb/myuser/mypassword [settings] ; alphanumeric without abiguous characters alphabet = 23456789abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNP
shortify-master.zip
  • shortify-master
  • .gitignore
    5B
  • README.md
    3.8KB
  • examples
  • postgres.gcfg
    211B
  • mysql.gcfg
    184B
  • sqlite3.gcfg
    174B
  • LICENSE
    1KB
  • app
  • database_test.go
    627B
  • encode_test.go
    465B
  • handlers_test.go
    4.9KB
  • redirect.go
    1.2KB
  • encode.go
    469B
  • handlers.go
    2.4KB
  • cli_test.go
    1.1KB
  • model_test.go
    478B
  • router.go
    1KB
  • cli.go
    2.3KB
  • config.go
    1.4KB
  • model.go
    204B
  • user.go
    1.7KB
  • user_test.go
    2.2KB
  • database.go
    2.4KB
  • config_test.go
    1.5KB
  • redirect_test.go
    2KB
  • shortify.go
    387B
  • script
  • bootstrap
    84B
  • test
    44B
  • build
    188B
  • .travis.yml
    26B
内容介绍
# Shortify [![Build Status](https://travis-ci.org/shortify/shortify.svg?branch=master)](https://travis-ci.org/shortify/shortify) [![GoDoc](https://godoc.org/github.com/shortify/shortify/app?status.svg)](https://godoc.org/github.com/shortify/shortify/app) A simple URL shortener application written in Go. ## Getting Started Head over to the [latest release] and download the `shortify` executable. [latest release]: https://github.com/shortify/shortify/releases/latest ### Building From Source ```bash git clone https://github.com/shortify/shortify.git script/build ``` ### Configuration In order to run shortify, you'll need to create a config file named `shortify.gcfg`. This file must be placed right beside the executable. Here's an example of a typical config file: ```ini [database] provider = mysql dataSource = tcp://localhost:3306*mydb/myuser/mypassword [settings] ; alphanumeric without abiguous characters alphabet = 23456789abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ port = 80 ``` Any of these settings can be supplied as an env var by using `$ENV_VAR_NAME` as the value. For example, if you have the following environment variables set: ```bash export SHORTIFY_DATASOURCE=tcp://localhost:3306*mydb/myuser/mypassword export SHORTIFY_PORT=8080 ``` Then you can use those values in the configuration like this: ```ini [database] provider = mysql dataSource = $SHORTIFY_DATASOURCE [settings] ; alphanumeric without abiguous characters alphabet = 23456789abcdefghijkmnpqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ port = $SHORTIFY_PORT ``` ### Running the App With the config file in place, simply run `./shortify`. If the database does not exist yet, shortify will create it for you. Currently, there is support for MySQL, PostgreSQL and Sqlite3. Very happy to receive PRs for others if you need them. For examples of how to configure each of these, check out the _examples/_ directory. ## Using Shortify Shortify is very simple. It has two endpoints: * `GET /{token}` - will redirect to the full URL for the specified token * `POST /redirects` - creates a new redirect (URLs are unique in this app) Creating redirects requires a valid user account (see below). To create a redirect, you'll need to set the auth header on the request and supply a JSON object with a `url` property. Here's an example using `CURL`: ```bash curl --user <username>:<password> \ -H "Content-Type: application/json" \ -d '{ "url": "http://pseudomuto.com/" }' \ http://localhost:8080/redirects ``` The result (if successful) will be a JSON object similar to this one: ```json { "id": 2, "token": "2Bk", "url": "http://pseudomuto.com/", "createdAt": "2015-04-12T22:41:36.544495662Z" } ``` After running the command above, you can browse to `http://localhost:8080/2Bk` and you will be redirected to `http://pseudomuto.com/`. **NOTE**: _tokens are case-sensitive (i.e. `2Bk` != `2bk`)_ Hopefully errors don't occur, but when they do, the response will have the correct HTTP status code and will have the following response body (code and text change depending on the error): ```json { "code": 404, "text": "Redirect was not found" } ``` ## Managing Users Creating a new `Redirect` record requires authentication. This app is configured to use basic authentication (read: should be served over SSL). Passwords are randomly generated and then hashed for storage in the database. * List all users - `./shortify users list` * Create a new user - `./shortify users create [username]` * Generate a new password for a user - `./shortify users resetpw [username]` _See `./shortify help` for options._ ## Logging Logs are very simple at this point. They include (tab seperated) the following information: * Timestamp * Request method * Request URL * The handler that handled the request * How long it took to execute Logs are written to `STDOUT` and no log file is kept.
评论
    相关推荐
    • H2Database内存数据库
      H2Database内存数据库jar包及示例.
    • shelter-database
      ~ /git$ git clone https://github.com/rodekruis/shelter-database.git ~ /git$ cd shelter-database/ ~ /git/shelter-database$ cp src/conf/conf.cfg-sample src/conf/conf.cfg ~ /git/shelter-database$ pipenv ...
    • Mckoi DataBase
      NULL 博文链接:https://yongjie.iteye.com/blog/668380
    • 数据库连接类DataBase
      NULL 博文链接:https://baobeituping.iteye.com/blog/801389
    • Mckoi DataBase
      NULL 博文链接:https://yongjie.iteye.com/blog/668380
    • database
      NULL 博文链接:https://vikingwei.iteye.com/blog/2297207
    • H2 Database Engine
      全名:H2 Database Engine 简约的效率的临时开发用的数据库 特点:开源,迅速。 两种模式,server,in-memory 有自己的控制台 jar包只有1M,非常的小巧
    • h2database Engine
      h2database Engine 1.2.133
    • Excel和Database双向读写
      NULL 博文链接:https://zranye.iteye.com/blog/1481562
    • Phishing.Database:https的测试
      关于网络钓鱼数据库 Testing repository for Phishing Domains, websites and threats. We use the PyFunceble testing tool to validate the status of all domains. 关于Ultimate-Hosts-Blacklist ...