Help us shape the future of Go! Take the 2026 Go Developer Survey

ifth

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2018 License: Apache-2.0 Imports: 6 Imported by: 0

README

Build Status

Short Url Service

This is a service to generate short url for long url.

中文文档

Demo:http://www.ifth.net

example

Features

  • Web page to generate short url
    • Choosing http/https
    • Choosing length (developing)
    • Custom ID (Scheduling)
  • API to generate short url(developing)
    • Length input

Installation

Build

Service is depended on MongoDB, please install first. Mongo Installation

  • Web page

    go get github.com/WindGreen/ifth
    cd www
    dep ensure
    chmod +x url && ./url
    

    this will listen the default port:8080, to change it by Configuration

  • Url Service

    go get github.com/WindGreen/ifth
    cd url
    dep ensure
    chmod +x www && ./www
    

    this will listen the default port:80, to change it by Configuration

Docker
  • Web page

    docker network create ifth
    docker run -d --name mongo --network ifth mongo
    docker run -d -p 80:80 --network ifth yqfwind/ifth-www:latest
    
  • Url Service

    docker network create ifth
    docker run -d --name mongo --network ifth mongo
    docker run -d -p 80:80 --network ifth yqfwind/ifth-url:latest
    

Configuration

  • Web page
mongodb:
  host: localhost
# www service
www:
  home: http://localhost:8080
  port: 8080
# url service
url:
  base: http://localhost/%s
  length: 3
  unique: true

www.home: the web page url

www.port: the web service listened on

url.base: the short url refers to, %s is the slot

url.length: the slot length

url.unique: TRUE or FALSE. FALSE means one url can has many short url linked to it.

  • Url Service
mongodb:
  host: localhost
# www service
www:
  home: http://localhost:8080
# url service
url:
  base: http://localhost/%s
  port: 80

url.port: the url service listened on

Documentation

Index

Constants

View Source
const (
	Random = iota
	AutoIncrement
)
View Source
const (
	RedirectProxy = "proxy"
	Redirect301   = "301"
	Redirect302   = "302"
	Redirect303   = "303"
	Redirect307   = "307"
)

Variables

This section is empty.

Functions

func GetMgo

func GetMgo() *mgo.Session

func InitSlotGenerator

func InitSlotGenerator(length, algorithm int, humanity bool)

func OriginExist

func OriginExist(origin string) bool

func SlotExist

func SlotExist(slot string) bool

Types

type App

type App struct {
	Name  string `json:"name"`
	Token string `json:"token"`
}

func NewApp

func NewApp(name string) *App

func (*App) Save

func (a *App) Save() error

type DB

type DB interface {
	Dial(dsn string) error
	Connect() (interface{}, error)
}
var Client DB

func InitMgo

func InitMgo(dsn string) (DB, error)

type GenFunc

type GenFunc func() string

type Mgo

type Mgo struct {
	Session *mgo.Session
}

func (*Mgo) Connect

func (m *Mgo) Connect() (interface{}, error)

func (*Mgo) Dial

func (m *Mgo) Dial(dsn string) error

type Slot

type Slot struct {
	Humanity  bool
	Length    int
	Algorithm int
	Letters   string
	Start     string
	// contains filtered or unexported fields
}
var SlotGenerator *Slot

func NewSlot

func NewSlot() *Slot

func (*Slot) Get

func (s *Slot) Get() string

func (*Slot) Run

func (s *Slot) Run()

type Url

type Url struct {
	Slot         string    `json:"slot"`
	Origin       string    `json:"origin"`
	RedirectType string    `json:"redirect_type" bson:"redirect_type"`
	CreatedTime  time.Time `json:"created_time" bson:"created_time"`
	ExpiresIn    int       `json:"expires_in" bson:"expires_in"`
	Count        int64     `json:"count"`
	Url          string    `json:"url" bson:"-"`
}

func FindHottestUrls

func FindHottestUrls(limit int) ([]Url, error)

func FindNewestUrls

func FindNewestUrls(limit int) ([]Url, error)

func FindUrlByOrigin

func FindUrlByOrigin(origin string) (*Url, error)

func FindUrlBySlot

func FindUrlBySlot(slot string) (*Url, error)

func NewCustomUrl

func NewCustomUrl(slot, origin string) *Url

func NewUrl

func NewUrl(origin string, unique bool) *Url

func (*Url) Expired

func (u *Url) Expired() bool

func (*Url) Save

func (u *Url) Save() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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