Merge branch 'html'
This commit is contained in:
commit
b5c58d079c
@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
|
|||||||
|
|
||||||
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
|
||||||
|
|
||||||
|
## 2019-03-18 - 0.0.3
|
||||||
|
|
||||||
|
### Added
|
||||||
|
|
||||||
|
- Add some html templates
|
||||||
|
|
||||||
## 2019-03-18 - 0.0.2
|
## 2019-03-18 - 0.0.2
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
FROM golang:1.12.1 as builder
|
FROM golang:1.12.4 as builder
|
||||||
|
|
||||||
ENV CGO_ENABLED=0
|
ENV CGO_ENABLED=0
|
||||||
|
|
||||||
ADD . /go/src/short
|
ADD main.go /go/src/short/
|
||||||
|
|
||||||
WORKDIR /go/src/short
|
WORKDIR /go/src/short
|
||||||
|
|
||||||
|
61
main.go
61
main.go
@ -23,9 +23,62 @@ const (
|
|||||||
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
|
letterIdxMax = 63 / letterIdxBits // # of letter indices fitting in 63 bits
|
||||||
)
|
)
|
||||||
const (
|
const (
|
||||||
appVersion = "0.0.1"
|
appVersion = "0.0.3"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const indexPage = `
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang=en>
|
||||||
|
<head>
|
||||||
|
<title>Short: the simple url shortener</title>
|
||||||
|
<style>
|
||||||
|
form{
|
||||||
|
position:fixed;
|
||||||
|
top:30%;
|
||||||
|
left:40%;
|
||||||
|
width:500px;
|
||||||
|
font-family:georgia,garamond,serif;
|
||||||
|
font-size:16px;
|
||||||
|
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<form action="/" method="POST">
|
||||||
|
<label for="url">
|
||||||
|
Please type the url</label>
|
||||||
|
<br>
|
||||||
|
<input id="url" type="text" name="url"/>
|
||||||
|
<input type="submit" name="Submit" value="Submit"/>
|
||||||
|
</form>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`
|
||||||
|
|
||||||
|
const returnPage = `
|
||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang=en>
|
||||||
|
<head>
|
||||||
|
<title>Short: the simple url shortner</title>
|
||||||
|
<style>
|
||||||
|
.center {
|
||||||
|
padding: 70px 0;
|
||||||
|
border: none;
|
||||||
|
border-color: transparent;
|
||||||
|
text-align: center;
|
||||||
|
font-family:georgia,garamond,serif;
|
||||||
|
font-size:16px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<div class="center">
|
||||||
|
URL Shortened to <a href="%s">%s</a>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
`
|
||||||
|
|
||||||
var domain string
|
var domain string
|
||||||
var redisServer string
|
var redisServer string
|
||||||
var listenAddr string
|
var listenAddr string
|
||||||
@ -34,6 +87,7 @@ var path string
|
|||||||
var src = rand.NewSource(time.Now().UnixNano())
|
var src = rand.NewSource(time.Now().UnixNano())
|
||||||
var pool = newPool()
|
var pool = newPool()
|
||||||
|
|
||||||
|
func index() string { return indexPage }
|
||||||
func newPool() *redis.Pool {
|
func newPool() *redis.Pool {
|
||||||
return &redis.Pool{
|
return &redis.Pool{
|
||||||
// Maximum number of idle connections in the pool.
|
// Maximum number of idle connections in the pool.
|
||||||
@ -131,7 +185,9 @@ func shortner(ctx *web.Context) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.Abort(500, "Internal Error")
|
ctx.Abort(500, "Internal Error")
|
||||||
} else {
|
} else {
|
||||||
ctx.WriteString("URL shortened at: " + proto + "://" + domain + port + path + suffix + "\n")
|
shortend := proto + "://" + domain + port + path + suffix
|
||||||
|
output := fmt.Sprintf(returnPage, shortend, shortend)
|
||||||
|
ctx.WriteString(output)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -171,6 +227,7 @@ func main() {
|
|||||||
path = path + "/"
|
path = path + "/"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
web.Get("/", index)
|
||||||
web.Post("/", shortner)
|
web.Post("/", shortner)
|
||||||
web.Get("/(.*)", redirect)
|
web.Get("/(.*)", redirect)
|
||||||
log.Printf("Domain: %s, Redis: %s\n", domain, redisServer)
|
log.Printf("Domain: %s, Redis: %s\n", domain, redisServer)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user