Skip to content

Commit a0e29c8

Browse files
committed
Added Flags & Readme
1 parent a847bbc commit a0e29c8

File tree

6 files changed

+32
-12
lines changed

6 files changed

+32
-12
lines changed

README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Wiki Index
2+
This project has been created to play around with the Wikipedia dataset.
3+
The goal is to calculate the distance between two pages, that is, how many clicks are required
4+
to get from one page to the other by only using the links on each page.
5+
6+
First you should download the dataset, e.g. from [here](https://meta.wikimedia.org/wiki/Data_dump_torrents). Next, you can build and run the index:
7+
8+
```bash
9+
go build
10+
./WikiIndex -i ~/Downloads/simplewiki-20170820-pages-meta-current.xml.bz2
11+
```
12+
13+
After that, you can reach the web interface with [http://localhost:8080](http://localhost:8080).

app/http.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/pkg/errors"
99
)
1010

11-
func (a *App) Serve() error {
11+
func (a *App) Serve(address string) error {
1212
r := gin.Default()
1313

1414
r.GET("/", a.Root())
@@ -17,7 +17,7 @@ func (a *App) Serve() error {
1717
r.GET("/longest", a.Longest())
1818
//r.GET("/loooongest", a.LongestOverall())
1919

20-
return r.Run(":8080")
20+
return r.Run(address)
2121
}
2222

2323
func (a *App) Root() gin.HandlerFunc {

go.mod

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ require (
77
github.com/flosch/pongo2 v0.0.0-20190707114632-bbf5a6c351f4
88
github.com/gin-gonic/gin v1.4.0
99
github.com/gosimple/slug v1.9.0
10+
github.com/jessevdk/go-flags v1.4.0
1011
github.com/pkg/errors v0.8.1
1112
github.com/stretchr/testify v1.3.0
1213
)

go.sum

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ github.com/gosimple/slug v1.9.0/go.mod h1:AMZ+sOVe65uByN3kgEyf9WEBKBCSS+dJjMX9x4
3232
github.com/hashicorp/go-syslog v1.0.0/go.mod h1:qPfqrKkXGihmCqbJM2mZgkZGvKG1dFdvsLplgctolz4=
3333
github.com/hashicorp/golang-lru v0.0.0-20180201235237-0fb14efe8c47/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
3434
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
35+
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
36+
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
3537
github.com/jimstudt/http-authentication v0.0.0-20140401203705-3eca13d6893a/go.mod h1:wK6yTYYcgjHE1Z1QtXACPDjcFJyBskHEdagmnq3vsP8=
3638
github.com/json-iterator/go v1.1.6/go.mod h1:+SdeFBvtyEkXs7REEP0seUULqWtbJapLOCVDaaPEHmU=
3739
github.com/juju/errors v0.0.0-20181118221551-089d3ea4e4d5 h1:rhqTjzJlm7EbkELJDKMTU7udov+Se0xZkWmugr6zGok=

main.go

+13-9
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@ import (
77
"log"
88
"os"
99

10-
_ "github.com/flosch/pongo2"
10+
"github.com/jessevdk/go-flags"
1111
)
1212

13-
14-
//const filename = "testdata/enwiki-20190101-pages-articles-multistream.xml.bz2"
15-
const filename = "testdata/simplewiki-20170820-pages-meta-current.xml.bz2"
16-
//const filename = "testdata/sample.xml"
17-
13+
var options struct {
14+
Filename string `short:"i" long:"input" description:"Wikipedia XML dump (something ending in .xml.bz2)" required:"true"`
15+
Address string `short:"h" long:"http" description:"HTTP address" default:":8080"`
16+
}
1817

1918
func main() {
2019
if err := run(); err != nil {
@@ -23,9 +22,14 @@ func main() {
2322
}
2423

2524
func run() error {
25+
_, err := flags.Parse(&options)
26+
if err != nil {
27+
os.Exit(1)
28+
}
29+
2630
app := app.New()
2731

28-
f, err := os.Open(filename)
32+
f, err := os.Open(options.Filename)
2933
if err != nil {
3034
return err
3135
}
@@ -39,5 +43,5 @@ func run() error {
3943
f.Close()
4044
}()
4145

42-
return app.Serve()
43-
}
46+
return app.Serve(options.Address)
47+
}

view/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ <h5 class="card-title">Least referenced page</h5>
5050

5151
</div>
5252

53-
<h4>What can you do here?</h4>
53+
<h4 class="mb-3">What can you do here?</h4>
5454

5555
<div class="row">
5656

0 commit comments

Comments
 (0)