nf / goto Goto Github PK
View Code? Open in Web Editor NEWA URL shortening service
License: Apache License 2.0
A URL shortening service
License: Apache License 2.0
I can not compile the sample. Here is my patch.
I apply gofix on goto/*.go and try to fix bench.go manual.
--- a/bench/bench.go
+++ b/bench/bench.go
@@ -83,7 +83,7 @@ func get() {
if r.StatusCode != 302 {
log.Println("get: wrong StatusCode:", r.StatusCode)
}
if l := r.Header["Location"]; l != fooUrl {
if l := r.Header["Location"][0]; l != fooUrl {
log.Println("get: wrong Location:", l)
}
Is it not possible to avoid the use of sync.RWMutex
in this example and use channels instead? Would that not be more idiomatic?
I understand why you are using Mutex but was it not possible to use channels instead?
Hi,
Could you add the nginx config file, ala https://github.com/golang/gddo/blob/master/deploy/gddo.conf?
Reference -> http://nf.id.au/posts/2010/10/deploying-go-web-services-behind-nginx-under.html
Thanks in advance!
store.gob is a file opened with O_APPEND for writes and gobs are appended to it. But it looks like this confuses the gob decoder after the first execution of the program. When it runs, it creates a gob Encoder object, and each new gob encoder will always include the type information into the file content. The result is redundant type definitions in the file. So the file will look like this:
.gob type defs
.data
.data
<stop program, start again>
.gob type defs
.data
.data
As a result, the decoder shows a warning (extra data in buffer) and interrupts the decoding.
One possible solution is to write to a different file in each execution, but read from all of them during load(). Or alternatively load() could decode the file in logical blocks, each using a separate Decoder object.
(I don't know if you had plans to update this tool, but even if you don't I thought it was worth documenting this issue anyway.)
Hi Andrew. Can people copy this source code? Could you please clarify the license? It's actually pretty useful :-).
Thanks!
Running the following code does not write to the file in the first run but keeps adding to the file in all subsequent runs with 'extra data in buffer' error. The file size is zero after first run and keeps growing after that. This is because the file data is not being read into the map.
package main
import (
"fmt"
"gob"
"log"
"os"
"strconv"
)
var tm = make(tmap)
type tmap map[string]string
type rec struct {
name, id string
}
func writerec(name, id string) os.Error {
f, err := os.OpenFile("data.dat", os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666)
defer f.Close()
if err != nil {
log.Println("writefile method file creation error : ", err)
}
fmt.Println("Opened the file writing the record.")
e := gob.NewEncoder(f)
return e.Encode(rec{name, id})
}
func loadfile() {
f, err := os.OpenFile("data.dat", os.O_CREATE|os.O_RDWR|os.O_APPEND, 0666)
if err != nil {
log.Println("writefile method file creation error : ", err)
}
d := gob.NewDecoder(f)
var r rec
for {
if err := d.Decode(&r); err == nil {
tm[r.name] = r.id
}
}
defer f.Close()
return
}
func gendata(c int) {
val := "abcdefghijklmno"
key := "abcdefghijklmnopqrstuvwxyzabcdefghijklmno"
for i := 0; i < c; i++ {
add := strconv.Itoa(i)
a := key + add
if _, ok := tm[a]; ok {
fmt.Println(key + add + " " + "is present")
} else {
fmt.Println(key + add + " " + "is not present")
tm[a] = val
writerec(a, val)
}
}
}
func main() {
gendata(5)
gendata(10)
gendata(15)
}
goto doesn't save the counter used to decide what is the next short url, or "key", so each execution of the program starts creating short urls from "0".
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.