Skip to content

Commit

Permalink
added comments (#5)
Browse files Browse the repository at this point in the history
* added comments

* update workflow to go 1.18
  • Loading branch information
TomerHeber authored Oct 5, 2022
1 parent 22d6d3d commit b5e467b
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
- synchronize

env:
GO_VERSION: 1.19
GO_VERSION: 1.18

jobs:
unit-tests:
Expand Down
32 changes: 18 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,9 @@ A URL shortener library implemented in Go.
go get github.com/TomerHeber/go-short-url
```

## MongoDB

To store the mappings between short urls and their original urls, A MongoDB database is required.

## Development

Install `golangci-lint`:
Check [https://golangci-lint.run/usage/install/#local-installation](https://golangci-lint.run/usage/install/#local-installation) for installation instructions.
## Documentation

Install `pre-commit`:
Check [https://pre-commit.com/](https://pre-commit.com/) for installation instructions.

Enable the git pre commit hooks:
`pre-commit install `
Documentation is available at: [https://pkg.go.dev/github.com/TomerHeber/go-short-url](https://pkg.go.dev/github.com/TomerHeber/go-short-url)

## Example

Expand All @@ -47,4 +36,19 @@ It's a tiny webserver that generates short urls.
```
docker-compose up -d
go run ./example/main.go
```
```

## MongoDB

To store the mappings between short urls and their original urls, A MongoDB database is required.

## Development

Install `golangci-lint`:
Check [https://golangci-lint.run/usage/install/#local-installation](https://golangci-lint.run/usage/install/#local-installation) for installation instructions.

Install `pre-commit`:
Check [https://pre-commit.com/](https://pre-commit.com/) for installation instructions.

Enable the git pre commit hooks:
`pre-commit install `
2 changes: 2 additions & 0 deletions config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"go.mongodb.org/mongo-driver/x/mongo/driver/connstring"
)

// Config is used to customize the shortener.
// To create a config instance use `DefaultConfig()`.
type Config interface {
getConfig() *config

Expand Down
2 changes: 1 addition & 1 deletion short.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func NewShortener(config ...Config) (Shortener, error) {
var s shortner

s.host = ci.host
s.store, err = NewStore(ci.mongoUri, ci.host)
s.store, err = newStore(ci.mongoUri, ci.host)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion store.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func getMongoCollection(ctx context.Context, database *mongo.Database, name stri
return collection, nil
}

func NewStore(mongoUri string, name string) (Store, error) {
func newStore(mongoUri string, name string) (Store, error) {
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
defer cancel()

Expand Down
8 changes: 4 additions & 4 deletions store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@ func TestStore(t *testing.T) {

t.Run("NewStore", func(t *testing.T) {
uri := getRandomMongoURIForTesting()
_, err := NewStore(uri, "short.link")
_, err := newStore(uri, "short.link")
require.Nil(t, err)
_, err = NewStore(uri, "short.com")
_, err = newStore(uri, "short.com")
require.Nil(t, err)
_, err = NewStore(uri, "short.link")
_, err = newStore(uri, "short.link")
require.Nil(t, err)

client := mongoDbClientMap[uri]
Expand All @@ -64,7 +64,7 @@ func TestStore(t *testing.T) {
getStoreHelper := func(t *testing.T) Store {
t.Helper()
uri := getRandomMongoURIForTesting()
s, err := NewStore(uri, collectionName)
s, err := newStore(uri, collectionName)
require.Nil(t, err)
return s
}
Expand Down
2 changes: 2 additions & 0 deletions url_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import (
"time"
)

// UrlConfig may be used to customize the way a url is shortened.
// A UrlConfig instance can be created by calling `DefaultUrlConfig()`.
type UrlConfig interface {
getConfig() *urlConfig

Expand Down

0 comments on commit b5e467b

Please sign in to comment.