Skip to content

Commit

Permalink
Rename common package as isemaildisposable
Browse files Browse the repository at this point in the history
  • Loading branch information
th0th committed Aug 14, 2024
1 parent 6fe6da4 commit 4e98d4a
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
4 changes: 2 additions & 2 deletions cmd/restapi/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"github.com/gofiber/fiber/v2"
"github.com/gofiber/fiber/v2/middleware/recover"
"github.com/rs/zerolog/log"
"github.com/th0th/is-email-disposable/pkg/common"
"github.com/th0th/is-email-disposable/pkg/isemaildisposable"
"github.com/th0th/is-email-disposable/pkg/restapi/handler"
"github.com/th0th/is-email-disposable/pkg/service/domain"
)

func main() {
common.LogSetDefaults()
isemaildisposable.LogSetDefaults()

domainService, err := domain.New()
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/domain.go → pkg/isemaildisposable/domain.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package common
package isemaildisposable

type DomainService interface {
Check(emailOrDomain string) *DomainServiceCheckResult
Expand Down
2 changes: 1 addition & 1 deletion pkg/common/log.go → pkg/isemaildisposable/log.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package common
package isemaildisposable

import (
"strconv"
Expand Down
4 changes: 2 additions & 2 deletions pkg/restapi/handler/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package handler
import (
"github.com/go-errors/errors"
"github.com/gofiber/fiber/v2"
"github.com/th0th/is-email-disposable/pkg/common"
"github.com/th0th/is-email-disposable/pkg/isemaildisposable"
)

type indexQueryParams struct {
EmailOrDomain *string `query:"email"`
}

func Index(domainService common.DomainService) fiber.Handler {
func Index(domainService isemaildisposable.DomainService) fiber.Handler {
return func(c *fiber.Ctx) error {
queryParams := indexQueryParams{}
err := c.QueryParser(&queryParams)
Expand Down
8 changes: 4 additions & 4 deletions pkg/service/domain/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import (
"strings"

"github.com/go-errors/errors"
"github.com/th0th/is-email-disposable/pkg/common"
"github.com/th0th/is-email-disposable/pkg/isemaildisposable"
)

type service struct {
domainsMap map[string]bool
}

func New() (common.DomainService, error) {
func New() (isemaildisposable.DomainService, error) {
csvReader := csv.NewReader(strings.NewReader(domainsCsvFile))
records, err := csvReader.ReadAll()
if err != nil {
Expand All @@ -30,15 +30,15 @@ func New() (common.DomainService, error) {
}, nil
}

func (s *service) Check(emailOrDomain string) *common.DomainServiceCheckResult {
func (s *service) Check(emailOrDomain string) *isemaildisposable.DomainServiceCheckResult {
domain := emailOrDomain

atIndex := strings.LastIndex(emailOrDomain, "@")
if atIndex > -1 {
domain = emailOrDomain[atIndex+1:]
}

return &common.DomainServiceCheckResult{
return &isemaildisposable.DomainServiceCheckResult{
IsDisposable: s.domainsMap[domain],
}
}
Expand Down

0 comments on commit 4e98d4a

Please sign in to comment.