Help us shape the future of Go! Take the 2026 Go Developer Survey

server

package
v0.1.9 Latest Latest
Warning

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

Go to latest
Published: Sep 28, 2020 License: GPL-3.0 Imports: 30 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EmailVerificationSubject is the subject for verification emails
	EmailVerificationSubject = "Netsoc account verification"
	// EmailResetPasswordSubject is the subject for password reset emails
	EmailResetPasswordSubject = "Netsoc account password reset"
)

Variables

View Source
var (
	// EmailVerificationAPI is a template for an email with API-based verification
	EmailVerificationAPI = template.Must(template.New("email_verification.txt").Parse(`Hi {{.User.FirstName}},

Thanks for signing up to Netsoc! Here's your verification token: {{.Token}}

Regards,
The Netsoc Team
`))
	// EmailVerificationUI is a template for an email with UI-based verification
	EmailVerificationUI = template.Must(template.New("email_verification.txt").Parse(`Hi {{.User.FirstName}},

Thanks for signing up to Netsoc! Click the following link to verify your account: {{template "url" .}}

Regards,
The Netsoc Team
`))

	// EmailResetPasswordAPI is a template for an email with API-based password reset
	EmailResetPasswordAPI = template.Must(template.New("email_verification.txt").Parse(`Hi {{.User.FirstName}},

Here's your password reset token: {{.Token}}

If you didn't initiate the reset, you can ignore this email.

Regards,
The Netsoc Team
`))
	// EmailResetPasswordUI is a template for an email with UI-based password reset
	EmailResetPasswordUI = template.Must(template.New("email_verification.txt").Parse(`Hi {{.User.FirstName}},

Click the following link to reset your password: {{template "url" .}}

If you didn't initiate the reset, you can ignore this email.

Regards,
The Netsoc Team
`))
)

Functions

func ConfigDecoderOptions

func ConfigDecoderOptions(config *mapstructure.DecoderConfig)

ConfigDecoderOptions enables necessary mapstructure decode hook functions

func HTTPRequestAccepts

func HTTPRequestAccepts(r *http.Request, mime string) bool

HTTPRequestAccepts returns true if the given request accepts the provided MIME type

func JSONErrResponse

func JSONErrResponse(w http.ResponseWriter, err error, statusCode int)

JSONErrResponse Sends an `error` as a JSON object with a `message` property

func JSONResponse

func JSONResponse(w http.ResponseWriter, v interface{}, statusCode int)

JSONResponse Sends a JSON payload in response to a HTTP request

func ParseJSONBody

func ParseJSONBody(v interface{}, w http.ResponseWriter, r *http.Request) error

ParseJSONBody attempts to parse the request body as JSON

Types

type Config

type Config struct {
	LogLevel log.Level `mapstructure:"log_level"`

	PostgreSQL struct {
		Host         string
		User         string
		Password     string
		PasswordFile string `mapstructure:"password_file"`
		Database     string
		TimeZone     string
		DSNExtra     string `mapstructure:"dsn_extra"`

		SoftDelete bool `mapstructure:"soft_delete"`
	}

	Mail struct {
		From      string
		ReplyTo   string `mapstructure:"reply_to"`
		VerifyURL string `mapstructure:"verify_url"`
		ResetURL  string `mapstructure:"reset_url"`

		SMTP struct {
			Host     string
			Port     uint16
			Username string
			Password string
			TLS      bool

			PasswordFile string `mapstructure:"password_file"`
		}
	}

	HTTP struct {
		ListenAddress string `mapstructure:"listen_address"`
		CORS          struct {
			AllowedOrigins []string `mapstructure:"allowed_origins"`
		}
	}

	JWT struct {
		Key     []byte `mapstructure:"key"`
		KeyFile string `mapstructure:"key_file"`

		Issuer        string
		LoginValidity time.Duration `mapstructure:"login_validity"`
		EmailValidity time.Duration `mapstructure:"email_validity"`
	}

	RootPassword     string `mapstructure:"root_password"`
	RootPasswordFile string `mapstructure:"root_password_file"`

	ReservedUsernames []string `mapstructure:"reserved_usernames"`
}

Config defines iamd's configuration

func (*Config) JWTKeyFunc

func (c *Config) JWTKeyFunc() jwt.Keyfunc

JWTKeyFunc returns a function that will return the JWT key (for use with `jwt` package)

func (*Config) ReadSecrets

func (c *Config) ReadSecrets() error

ReadSecrets loads values for secret config options from files

type EmailUserInfo

type EmailUserInfo struct {
	User  *models.User
	Token string
}

EmailUserInfo represents information available to email templates

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents the iamd server

func NewServer

func NewServer(config Config) *Server

NewServer creates a new iamd server

func (*Server) SendEmail

func (s *Server) SendEmail(tpl *template.Template, subject string, info EmailUserInfo) error

SendEmail sends an email to a user

func (*Server) Start

func (s *Server) Start() error

Start starts the iamd server

func (*Server) Stop

func (s *Server) Stop() error

Stop shuts down the iamd server

Jump to

Keyboard shortcuts

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