Skip to content

Commit 6acfb34

Browse files
committed
Fix repository name and imports, improve code structure
- Fix repository name from ukeeper-redabilty to ukeeper-readability in all imports and go.mod - Introduce Stores struct to better organize DAOs - Update CLI flags format to use hyphen-separated-words instead of underscores - Update README to fix incorrect badge links - Change config parameters to use consistent naming conventions - Fix frontend-dir flag name in code to match README
1 parent c7e8d86 commit 6acfb34

File tree

10 files changed

+50
-25
lines changed

10 files changed

+50
-25
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
## ukeeper-readability [![build](https://github.com/ukeeper/ukeeper-redabilty/actions/workflows/ci.yml/badge.svg)](https://github.com/ukeeper/ukeeper-redabilty/actions/workflows/ci.yml) [![Coverage Status](https://coveralls.io/repos/github/ukeeper/ukeeper-readability/badge.svg?branch=master)](https://coveralls.io/github/ukeeper/ukeeper-readability?branch=master)
1+
## ukeeper-readability [![build](https://github.com/ukeeper/ukeeper-readability/actions/workflows/ci.yml/badge.svg)](https://github.com/ukeeper/ukeeper-readability/actions/workflows/ci.yml) [![Coverage Status](https://coveralls.io/repos/github/ukeeper/ukeeper-readability/badge.svg?branch=master)](https://coveralls.io/github/ukeeper/ukeeper-readability?branch=master)
22

33
### Running instructions
44

@@ -10,8 +10,8 @@
1010
|--------------|-----------------|----------------|-------------------------------------------------------|
1111
| address | UKEEPER_ADDRESS | all interfaces | web server listening address |
1212
| port | UKEEPER_PORT | `8080` | web server port |
13-
| mongo_uri | MONGO_URI | none | MongoDB connection string, _required_ |
14-
| frontend_dir | FRONTEND_DIR | `/srv/web` | directory with frontend files |
13+
| mongo-uri | MONGO_URI | none | MongoDB connection string, _required_ |
14+
| frontend-dir | FRONTEND_DIR | `/srv/web` | directory with frontend files |
1515
| token | TOKEN | none | token for /content/v1/parser endpoint auth |
1616
| mongo-delay | MONGO_DELAY | `0` | mongo initial delay |
1717
| mongo-db | MONGO_DB | `ureadability` | mongo database name |

backend/datastore/mongo.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,22 @@ func New(connectionURI, dbName string, delay time.Duration) (*MongoServer, error
3737
return &MongoServer{client: client, dbName: dbName}, nil
3838
}
3939

40+
// Stores contains all DAO instances
41+
type Stores struct {
42+
Rules RulesDAO
43+
}
44+
4045
// GetStores initialize collections and make indexes
41-
func (m *MongoServer) GetStores() (rules RulesDAO) {
46+
func (m *MongoServer) GetStores() Stores {
4247
rIndexes := []mongo.IndexModel{
4348
{Keys: bson.D{{Key: "enabled", Value: 1}, {Key: "domain", Value: 1}}},
4449
{Keys: bson.D{{Key: "user", Value: 1}, {Key: "domain", Value: 1}, {Key: "enabled", Value: 1}}},
4550
{Keys: bson.D{{Key: "domain", Value: 1}, {Key: "match_urls", Value: 1}}},
4651
}
47-
rules = RulesDAO{Collection: m.collection("rules", rIndexes)}
48-
return rules
52+
53+
return Stores{
54+
Rules: RulesDAO{Collection: m.collection("rules", rIndexes)},
55+
}
4956
}
5057

5158
// collection makes collection with indexes

backend/datastore/rules_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ func TestRules(t *testing.T) {
1919
server, err := New("mongodb://localhost:27017/", "test_ureadability", 0)
2020
require.NoError(t, err)
2121
assert.NotNil(t, server.client)
22-
rules := server.GetStores()
22+
stores := server.GetStores()
23+
assert.NotNil(t, stores)
24+
rules := stores.Rules
2325
assert.NotNil(t, rules)
2426
rule := Rule{
2527
Domain: randStringBytesRmndr(42) + ".com",
@@ -74,7 +76,9 @@ func TestRulesCanceledContext(t *testing.T) {
7476
server, err := New("mongodb://wrong", "", 0)
7577
require.NoError(t, err)
7678
assert.NotNil(t, server.client)
77-
rules := server.GetStores()
79+
stores := server.GetStores()
80+
assert.NotNil(t, stores)
81+
rules := stores.Rules
7882
assert.NotNil(t, rules)
7983

8084
ctx, cancel := context.WithCancel(context.Background())

backend/extractor/readability.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import (
1616
"github.com/mauidude/go-readability"
1717
"go.mongodb.org/mongo-driver/bson/primitive"
1818

19-
"github.com/ukeeper/ukeeper-redabilty/backend/datastore"
19+
"github.com/ukeeper/ukeeper-readability/backend/datastore"
2020
)
2121

2222
// Rules interface with all methods to access datastore
@@ -56,7 +56,9 @@ var (
5656
reDot = regexp.MustCompile(`\D(\.)\S`)
5757
)
5858

59-
const userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15"
59+
const (
60+
userAgent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.4 Safari/605.1.15"
61+
)
6062

6163
// Extract fetches page and retrieves article
6264
func (f *UReadability) Extract(ctx context.Context, reqURL string) (*Response, error) {

backend/extractor/readability_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
"github.com/stretchr/testify/require"
1616
"go.mongodb.org/mongo-driver/bson/primitive"
1717

18-
"github.com/ukeeper/ukeeper-redabilty/backend/datastore"
18+
"github.com/ukeeper/ukeeper-readability/backend/datastore"
1919
)
2020

2121
func TestExtractURL(t *testing.T) {

backend/go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
module github.com/ukeeper/ukeeper-redabilty/backend
1+
module github.com/ukeeper/ukeeper-readability/backend
22

33
go 1.23.0
44

backend/main.go

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,20 @@ import (
1111
log "github.com/go-pkgz/lgr"
1212
"github.com/jessevdk/go-flags"
1313

14-
"github.com/ukeeper/ukeeper-redabilty/backend/datastore"
15-
"github.com/ukeeper/ukeeper-redabilty/backend/extractor"
16-
"github.com/ukeeper/ukeeper-redabilty/backend/rest"
14+
"github.com/ukeeper/ukeeper-readability/backend/datastore"
15+
"github.com/ukeeper/ukeeper-readability/backend/extractor"
16+
"github.com/ukeeper/ukeeper-readability/backend/rest"
1717
)
1818

1919
var revision string
2020

2121
var opts struct {
2222
Address string `long:"address" env:"UKEEPER_ADDRESS" default:"" description:"listening address"`
2323
Port int `long:"port" env:"UKEEPER_PORT" default:"8080" description:"port"`
24-
FrontendDir string `long:"frontend_dir" env:"FRONTEND_DIR" default:"/srv/web" description:"directory with frontend templates and static/ directory for static assets"`
24+
FrontendDir string `long:"frontend-dir" env:"FRONTEND_DIR" default:"/srv/web" description:"directory with frontend templates and static/ directory for static assets"`
2525
Credentials map[string]string `long:"creds" env:"CREDS" description:"credentials for protected calls (POST, DELETE /rules)"`
2626
Token string `long:"token" env:"UKEEPER_TOKEN" description:"token for /content/v1/parser endpoint auth"`
27-
MongoURI string `short:"m" long:"mongo_uri" env:"MONGO_URI" required:"true" description:"MongoDB connection string"`
27+
MongoURI string `short:"m" long:"mongo-uri" env:"MONGO_URI" required:"true" description:"MongoDB connection string"`
2828
MongoDelay time.Duration `long:"mongo-delay" env:"MONGO_DELAY" default:"0" description:"mongo initial delay"`
2929
MongoDB string `long:"mongo-db" env:"MONGO_DB" default:"ureadability" description:"mongo database name"`
3030
Debug bool `long:"dbg" env:"DEBUG" description:"debug mode"`
@@ -46,8 +46,13 @@ func main() {
4646
if err != nil {
4747
log.Fatalf("[ERROR] can't connect to mongo %v", err)
4848
}
49+
stores := db.GetStores()
4950
srv := rest.Server{
50-
Readability: extractor.UReadability{TimeOut: 30 * time.Second, SnippetSize: 300, Rules: db.GetStores()},
51+
Readability: extractor.UReadability{
52+
TimeOut: 30 * time.Second,
53+
SnippetSize: 300,
54+
Rules: stores.Rules,
55+
},
5156
Token: opts.Token,
5257
Credentials: opts.Credentials,
5358
Version: revision,

backend/main_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ func Test_Main(t *testing.T) {
2323

2424
port := chooseRandomUnusedPort()
2525
os.Args = []string{"test", "--port=" + strconv.Itoa(port), "--dbg",
26-
"--mongo_uri=mongodb://localhost:27017/",
26+
"--mongo-uri=mongodb://localhost:27017/",
2727
"--mongo-db=test_ureadability",
28-
"--frontend_dir=web",
28+
"--frontend-dir=web",
2929
}
3030

3131
done := make(chan struct{})

backend/rest/server.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ import (
1818
"github.com/go-pkgz/routegroup"
1919
"go.mongodb.org/mongo-driver/bson/primitive"
2020

21-
"github.com/ukeeper/ukeeper-redabilty/backend/datastore"
22-
"github.com/ukeeper/ukeeper-redabilty/backend/extractor"
21+
"github.com/ukeeper/ukeeper-readability/backend/datastore"
22+
"github.com/ukeeper/ukeeper-readability/backend/extractor"
2323
)
2424

2525
// Server is a basic rest server providing access to store and invoking parser
@@ -176,6 +176,7 @@ func (s *Server) extractArticle(w http.ResponseWriter, r *http.Request) {
176176
// if token is not set for application, it won't be checked
177177
func (s *Server) extractArticleEmulateReadability(w http.ResponseWriter, r *http.Request) {
178178
token := r.URL.Query().Get("token")
179+
179180
if s.Token != "" && token == "" {
180181
rest.SendErrorJSON(w, r, log.Default(), http.StatusExpectationFailed, nil, "no token passed")
181182
return

backend/rest/server_test.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import (
1919
"github.com/stretchr/testify/assert"
2020
"github.com/stretchr/testify/require"
2121

22-
"github.com/ukeeper/ukeeper-redabilty/backend/datastore"
23-
"github.com/ukeeper/ukeeper-redabilty/backend/extractor"
22+
"github.com/ukeeper/ukeeper-readability/backend/datastore"
23+
"github.com/ukeeper/ukeeper-readability/backend/extractor"
2424
)
2525

2626
const letterBytes = "abcdefghijklmnopqrstuvwxyz"
@@ -615,8 +615,14 @@ func startupT(t *testing.T) (*httptest.Server, *Server) {
615615

616616
db, err := datastore.New("mongodb://localhost:27017/", "test_ureadability", 0)
617617
require.NoError(t, err)
618+
619+
stores := db.GetStores()
618620
srv := Server{
619-
Readability: extractor.UReadability{TimeOut: 30 * time.Second, SnippetSize: 300, Rules: db.GetStores()},
621+
Readability: extractor.UReadability{
622+
TimeOut: 30 * time.Second,
623+
SnippetSize: 300,
624+
Rules: stores.Rules,
625+
},
620626
Credentials: map[string]string{"admin": "password"},
621627
Version: "dev-test",
622628
}

0 commit comments

Comments
 (0)