mailx

package module
v0.0.0-...-2eb00bf Latest Latest
Warning

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

Go to latest
Published: Apr 2, 2022 License: Apache-2.0 Imports: 8 Imported by: 0

README

mailx-google-service

mailx-google-service is an open-source microservice that consumes the Gmail API for an open-souce email client Mailx

mailx-google-service tools

mailx-google-service uses multiple libraries and tools to work such as:

  • gorila mux for a multiplexer router.
  • go-kit standard library for microservices architecture.
  • sqlx an extension for database/sqlgolang package.
  • goose for incremental or decremental migrations.
  • pq driver for a postgres database.
  • oauth2 for authorization.

Getting started

To get started with mailx-google-service is important to have the following tools installed in your machine:

  • go v1.17+ (primary programming language)
  • Docker
  • goose (migration tool)

Clone the project in your desired location such as on $GOPATH:

git clone https://github.com/orlandorode97/mailx-google-service.git

mailx-google-services requires a .env at the root of the project with the following variables:

POSTGRES_USER=
POSTGRES_PASSWORD=
POSTGRES_HOST=mailx-google-service-db-1
POSTGRES_HOST_GOOSE=localhost
POSTGRES_PORT=5432
POSTGRES_DB_NAME=postgres
POSTGRES_SSL_MODE=disable
POSTGRES_DB_SCHEMA=public


GOOGLE_REDIRECT_URL=
GOOGLE_CLIENT_ID=
GOOGLE_CLIENT_SECRET=

After setting up the .env at the root the project run:

make build-run

The previous command builds a mailx-google-service container along with another container for a postgres database. Check the Makefile for more available commands.

Migrations

To perform migrations it's required to have installed goose in your machine. Check tools section. To create a migration file run the following command:

goose create migration_file_name

The previous command will generate a go file where the needed sql statements will be placed. This migration has the following format yyyymmddhhmmss_migration_name.go and is created at the root of the project, you should move the migration file into the migrations folder.

When the container mailx-google-service is up and running run the follwing command to run a migration:

make goose-up

Your terminal should print something like:

Building goose binary --->
go build -o . ./cmd/goose
Goose binary built
Up migrations
./goose up
<nil>
2022/01/25 00:48:59 OK    20220124004601_google_users_table.go
2022/01/25 00:48:59 OK    20220124234200_google_auth_users_table.go
2022/01/25 00:48:59 OK    20220124235821_auth_users_relation.go
2022/01/25 00:48:59 goose: no migrations to run. current version: 20220124235821
Migrations up successfully

TODO

A lot of things 😳

Documentation

Index

Constants

View Source
const (
	UserInfoUrl = "https://www.googleapis.com/oauth2/v2/userinfo?access_token="
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Creator

type Creator interface {
	// CreateGmailService returns a new gmail service instance.
	CreateGmailService(*oauth2.Token) (google.Service, error)
	// RecreateGmailService returns a new gmail service when a service is not attached to a user
	RecreateGmailService(context.Context, string) (google.Service, error)
}

type Getter

type Getter interface {
	// GetGmailService returns a pointer of gmail service.
	GetGmailService(string) google.Service
}

type Service

type Service interface {
	Creator
	Getter
	Setter
}

func New

func New(logger log.Logger, repo repos.TokenRepository, config *oauth2.Config) Service

type Setter

type Setter interface {
	// AddGmailServiceByID creates a new entry of a pointer gmail service by google user ID.
	AddGmailServiceByID(string, google.Service) google.Service
}

Directories

Path Synopsis
cmd
pkg

Jump to

Keyboard shortcuts

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