Skip to content

Commit

Permalink
feat: add api for subjects browsing (#564)
Browse files Browse the repository at this point in the history
Co-authored-by: Trim21 <trim21.me@gmail.com>
  • Loading branch information
everpcpc and trim21 authored Jun 2, 2024
1 parent d9647c6 commit 2ba3be4
Show file tree
Hide file tree
Showing 19 changed files with 975 additions and 6 deletions.
25 changes: 25 additions & 0 deletions Taskfile.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,31 @@ tasks:
env:
CGO_ENABLED: "0"

web:
desc: Run Web Server
aliases:
- serve
- server
cmds:
- go run main.go --config config.yaml web

consumer:
desc: Run Kafka Consumer
aliases:
- canal
cmds:
- go run main.go canal --config config.yaml

openapi-test:
desc: Test OpenAPI Schema
cmds:
- npm run test

openapi:
desc: Build OpenAPI Schema
cmds:
- npm run build

bench:
desc: Run benchmark
cmds:
Expand Down
8 changes: 8 additions & 0 deletions internal/cachekey/cachekey.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,14 @@ func Subject(id model.SubjectID) string {
return resPrefix + "subject:" + strconv.FormatUint(uint64(id), 10)
}

func SubjectBrowse(s string, limit, offset int) string {
return resPrefix + "subject::browse:" + s + ":" + strconv.Itoa(limit) + ":" + strconv.Itoa(offset)
}

func SubjectBrowseCount(s string) string {
return resPrefix + "subject::browse:" + s + "::count"
}

func Episode(id model.EpisodeID) string {
return resPrefix + "episode:" + strconv.FormatUint(uint64(id), 10)
}
Expand Down
118 changes: 118 additions & 0 deletions internal/mocks/SubjectCachedRepo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

118 changes: 118 additions & 0 deletions internal/mocks/SubjectRepo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions internal/pkg/gstr/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,38 @@ import (
"github.com/trim21/errgo"
)

func ParseInt8(s string) (int8, error) {
v, err := strconv.ParseInt(s, 10, 8)

return int8(v), errgo.Wrap(err, "strconv")
}

func ParseUint8(s string) (uint8, error) {
v, err := strconv.ParseUint(s, 10, 8)

return uint8(v), errgo.Wrap(err, "strconv")
}

func ParseUint16(s string) (uint16, error) {
v, err := strconv.ParseUint(s, 10, 16)

return uint16(v), errgo.Wrap(err, "strconv")
}

func ParseInt32(s string) (int32, error) {
v, err := strconv.ParseInt(s, 10, 32)

return int32(v), errgo.Wrap(err, "strconv")
}

func ParseUint32(s string) (uint32, error) {
v, err := strconv.ParseUint(s, 10, 32)

return uint32(v), errgo.Wrap(err, "strconv")
}

func ParseBool(s string) (bool, error) {
v, err := strconv.ParseBool(s)

return v, errgo.Wrap(err, "strconv")
}
Loading

0 comments on commit 2ba3be4

Please sign in to comment.