βββ common # common package holding common, utility components.
βββ users # users package holding users-related components.
π¨βπ»
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package users | |
// UserRepository abstracts accesses to users-related data. | |
type UserRepository interface { | |
ExistsByUsername(string) (bool, error) | |
ExistsByEmail(string) (bool, error) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Errors. | |
var ( | |
ErrUsernameIsTooShort = errors.New("username must be at least 1-character length") | |
ErrUsernameIsTooLong = errors.New("username must be at most 32-character length") | |
ErrUsernameContainsInvalidChar = errors.New("username must contain only digits, underscores, dashes, dots and alphabetical letters") | |
ErrUsernameBeginsWithInvalidChar = errors.New("username must begin with either underscore or an alphabetical letter") | |
ErrEmailIsInvalid = errors.New("email is invalid") | |
ErrEmailIsTooLong = errors.New("email must be at most 128-character length") | |
ErrFullNameIsTooShort = errors.New("full name must be at least 1-character length") | |
ErrFullNameIsTooLong = errors.New("full name must be at most 128-character length") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package users | |
import ( | |
"github.com/stretchr/testify/assert" | |
"testing" | |
) | |
func TestValidateUser(t *testing.T) { | |
tests := []struct { | |
user User |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package users | |
import ( | |
"errors" | |
"regexp" | |
"github.com/the-evengers/go-restful/common" | |
) | |
// ... other stuff ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package common | |
import "fmt" | |
// Errors is a collection of errors. | |
type Errors []error | |
func (errs Errors) Error() string { | |
msgs := make([]string, len(errs)) | |
for i, err := range errs { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package users | |
import ( | |
"errors" | |
"regexp" | |
) | |
// Regular expressions. | |
var ( | |
regexContainsOnlyDigitsUnderscoreDashesDotsAlpha = regexp.MustCompile(`^[0-9a-zA-Z_\.\-]*$`) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package users | |
// User holds a user's data. | |
type User struct { | |
Username string | |
Email string | |
FullName string | |
Bio string | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
FROM golang:1 | |
# Configure to avoid build warnings and errors as described in official VSCode Remote-Containers extension documentation. | |
# See https://code.visualstudio.com/docs/remote/containers-advanced#_reducing-dockerfile-build-warnings. | |
ENV DEBIAN_FRONTEND=noninteractive | |
RUN apt-get update \ | |
&& apt-get -y install --no-install-recommends apt-utils 2>&1 | |
# Verify git, process tools, lsb-release (common in install instructions for CLIs) installed. | |
RUN apt-get -y install git iproute2 procps lsb-release |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module github.com/the-evengers/go-restful | |
go 1.13 | |
require github.com/gorilla/mux v1.7.3 |