fix up expiry

This commit is contained in:
Eliot Whalan 2016-07-15 13:06:25 +10:00
parent 99bcfa067f
commit e86b94784d
4 changed files with 25 additions and 14 deletions

View File

@ -13,6 +13,7 @@ install:
go get github.com/ewhal/pygments go get github.com/ewhal/pygments
go get github.com/go-sql-driver/mysql go get github.com/go-sql-driver/mysql
go get github.com/gorilla/mux go get github.com/gorilla/mux
go get github.com/ChannelMeter/iso8601duration
test: install test: install
go test $(GOFLAGS) ./... go test $(GOFLAGS) ./...

View File

@ -451,12 +451,13 @@
</select> </select>
<select id="expiry" name="expiry" class="form-control"> <select id="expiry" name="expiry" class="form-control">
<option value="1h">1 hour</option> <option value="5M">5 minutes</option>
<option value="24h">1 day</option> <option value="1H">1 hour</option>
<option value="1w">1 week</option> <option value="1D">1 day</option>
<option value="1m">1 month</option> <option value="1W">1 week</option>
<option value="12m">1 year</option> <option value="30D">1 month</option>
<option value="240m" selected>Forever</option> <option value="1Y">1 year</option>
<option value="20Y" selected>Forever</option>
</select> </select>
<button type="submit" class="btn btn-raised btn-primary">Submit<div class="ripple-container"></div></button> <button type="submit" class="btn btn-raised btn-primary">Submit<div class="ripple-container"></div></button>

View File

@ -450,12 +450,13 @@
</select> </select>
<select id="expiry" name="expiry" class="form-control"> <select id="expiry" name="expiry" class="form-control">
<option value="1h">1 hour</option> <option value="5M">5 minutes</option>
<option value="24h">1 day</option> <option value="1H">1 hour</option>
<option value="1w">1 week</option> <option value="1D">1 day</option>
<option value="1m">1 month</option> <option value="1W">1 week</option>
<option value="12m">1 year</option> <option value="30d">1 month</option>
<option value="240m" selected>Forever</option> <option value="1Y">1 year</option>
<option value="20Y" selected>Forever</option>
</select> </select>
<button type="submit" class="btn btn-raised btn-primary">Submit<div class="ripple-container"></div></button> <button type="submit" class="btn btn-raised btn-primary">Submit<div class="ripple-container"></div></button>
</div> </div>

View File

@ -16,6 +16,7 @@ import (
"net/http" "net/http"
"time" "time"
duration "github.com/channelmeter/iso8601duration"
// uniuri is used for easy random string generation // uniuri is used for easy random string generation
"github.com/dchest/uniuri" "github.com/dchest/uniuri"
// pygments is used for syntax highlighting // pygments is used for syntax highlighting
@ -136,8 +137,15 @@ func Save(raw string, lang string, title string, expiry string) Response {
} }
const timeFormat = "2006-01-02 15:04:05" const timeFormat = "2006-01-02 15:04:05"
duration, err := time.ParseDuration(expiry)
Check(err) expiry = "P" + expiry
dura, err := duration.FromString(expiry) // dura is time.Duration type
if err != nil {
fmt.Println("Error : ", err)
}
duration := dura.ToDuration()
expiryTime := time.Now().Add(duration).Format(timeFormat) expiryTime := time.Now().Add(duration).Format(timeFormat)
delKey := uniuri.NewLen(40) delKey := uniuri.NewLen(40)