graphql_twitter

package module
v0.0.0-...-48c0a4b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 15, 2022 License: MIT Imports: 6 Imported by: 0

README

graphql-twitter

follow this tutorial: https://store.equimper.com/view/courses/build-a-twitter-clone-graphql-api-using-golang/765944-introduction/2238834-go-modules

Folder structure

  • cmd
    root folder which is our program start entrypoint
  • config
    app configuration globally accessible for our app like database url, JWT secret etc.
  • domain
    business logic inside this folder
    • domain use interface to do it logic, decoupling the implementation from repo folder, easy to mock unit test
    • domain also implemented the graphql interface, decoupling the implementation from graphql-handler
    • graphql logic for handler to call, we don't want to add all logic inside our graphql layer.
      We create the domain layer to encapsulate all functions for graphql-handler to call.
      This will let you easily switch from graphql to restful api in the future.
  • postgres
    All repo function talk to database will place in here.
    Create MongoDB, MySql folder if you need to communicate with different dbs
  • auth.go, user.go All Interface place in here which will be used by repo layer or domain layer
    We also have input Validation and Sanitize function in here for repo or domain layer to use.
    This way to prevent circular dependency.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	UsernameMinLength = 2
	PasswordMinLength = 6
)
View Source
var (
	ErrBadCredentials = errors.New("email or password wrong combination")
	ErrNotFound       = errors.New("not found")
	ErrValidation     = errors.New("validation error")
)
View Source
var (
	ErrUsernameTaken = errors.New("username taken")
	ErrEmailTaken    = errors.New("email taken")
)

Functions

This section is empty.

Types

type AuthResponse

type AuthResponse struct {
	AccessToken string
	User        User
}

type AuthService

type AuthService interface {
	Register(ctx context.Context, input RegisterInput) (AuthResponse, error)
	Login(ctx context.Context, input LoginInput) (AuthResponse, error)
}

type LoginInput

type LoginInput struct {
	Email    string
	Password string
}

func (*LoginInput) Sanitize

func (in *LoginInput) Sanitize()

Sanitize will update the RegisterInput so we need pointer

func (LoginInput) Validate

func (in LoginInput) Validate() error

Validate no need to change RegisterInput so we do not need pointer

type RegisterInput

type RegisterInput struct {
	Email           string
	Username        string
	Password        string
	ConfirmPassword string
}

func (*RegisterInput) Sanitize

func (in *RegisterInput) Sanitize()

Sanitize will update the RegisterInput so we need pointer

func (RegisterInput) Validate

func (in RegisterInput) Validate() error

Validate no need to change RegisterInput so we do not need pointer

type User

type User struct {
	ID        string
	Username  string
	Email     string
	Password  string
	CreatedAt time.Time
	UpdatedAt time.Time
}

type UserRepo

type UserRepo interface {
	Create(ctx context.Context, user User) (User, error)
	GetByUsername(ctx context.Context, username string) (User, error)
	GetByEmail(ctx context.Context, email string) (User, error)
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL