Skip to content

Instantly share code, notes, and snippets.

@MAAARKIN
Created April 5, 2020 00:12
Show Gist options
  • Save MAAARKIN/c193bb8ca230d22947d6435dedb60a49 to your computer and use it in GitHub Desktop.
Save MAAARKIN/c193bb8ca230d22947d6435dedb60a49 to your computer and use it in GitHub Desktop.
package service
import (
"github.com/maaarkin/errors-handling/pkg/domains/todo"
"github.com/pkg/errors"
)
//TodoService representa o servico que poderá ser exporto para a camada de consumo (rest, grpc, rabbitmq, etc...)
type TodoService interface {
Save(title string) (*todo.Todo, error)
}
type todoService struct {
}
//NewTodoService função que tem como responsabilidade inicializar a interface do TodoService
func NewTodoService() TodoService {
return todoService{}
}
func (t todoService) Save(value string) (*todo.Todo, error) {
if value == "" {
return nil, errors.WithStack(todo.TodoTitleError{})
}
if value == "teste" {
return nil, todo.TodoTitleError{}
}
out := todo.Todo{
Title: value,
}
return &out, nil
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment