fast-utils

module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 31, 2022 License: MIT

README

fast-utils

License

Install

Go version 1.18+

go get github.com/Seifbarouni/[email protected]

Examples

Using the GetVariable function to get a config variable from a file generated by a configMap
package main

import u "github.com/Seifbarouni/fast-utils/utils"

func main(){
        str,err:=u.GetVariable(".","CONFIG")
        if err!=nil{
                panic(err)
        }
        println(str)
}
Using the SendEmail function
package main

import u "github.com/Seifbarouni/fast-utils/utils"

func main(){
	err:= u.SendEmail(
		"[email protected]",
		"[email protected]",
		"gmail application password",
		"subject",
		"body",
	)
	if err!=nil{
		panic(err)
	}
}
Send email with an HTML template using the SendEmailWithTemplate function
<!-- template.html -->
<!DOCTYPE html>
<html>
  <body>
    <h3 style="color: red">Name:</h3>
    <span>{{.Name}}</span><br /><br />
    <h3 style="color: blue">Email:</h3>
    <span>{{.Message}}</span><br />
  </body>
</html>

Generate a *template.Template variable from the template.html file and pass it to the function:

package main

import (
	"text/template"

	u "github.com/Seifbarouni/fast-utils/utils"
)

func main() {
	//Provide path to your template
	t, _ := template.ParseFiles("template.html")
	//The data parameter must be a struct and must match the html template
	//For more information visit https://golangdocs.com/templates-in-golang
	err := u.SendEmailWithTemplate(
		"[email protected]",
		"[email protected]",
		"gmail application password",
		"subject",
		t,
		struct {
			Name    string
			Message string
		}{
			Name:    "Seif",
			Message: "Hello World",
		},
	)
	if err != nil {
		panic(err)
	}
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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