Go Language

Envío de email con sendmail y golang

Con este pequeña utilidad se podrá realizar el envío de emails mediante golang y sendmail

import (
  "os"
  "exec"
  "fmt"
  "io"
)

func SendEmail() {
  argv := []string {"sendmail","-t"}

  cmd, err := exec.LookPath(argv[0])
  if err != nil {
    fatal("exec %s: %s", argv[0], err)
  }
  r,w,err := os.Pipe()
  if err !=nil {
    fatal("%v",err)
  }
  pid, err := os.ForkExec(cmd,argv,os.Environ(), "", []*os.File{r, os.Stdout, os.Stderr})
  if err != nil {
    fatal("%s", err)
  }
  input,err := os.Open("myEmail.txt", os.O_RDONLY, 0666)
  _, err = io.Copy(w, input)
  if err != nil {
    fatal("%v",err)
  }
  w.Close()
  os.Wait(pid, 0)
}

// Control de errores
func fatal(msg string, args ...interface{}) {
    fmt.Fprintf(os.Stderr, msg+"\n", args)
    os.Exit(2)
}

CouchDB Api para Go Language

Peter Bourgon, ha desarrollado una API para Go Language que nos permite trabajar con CouchDB.

Para los que no conozcan CouchDB, podemos resumirlo como “una base de datos documental sin ‘esquema’, consultable al estilo MapReduce, accesible por REST y con una funcionalidad de replicación integrada”.

Primeros Pasos:

//Primero creamos un objeto database para acceder a nuestra bd:
db, err := couch.NewDatabase("127.0.0.1", "5984", "databasename")

Memory Profiling Go Languaje

If you are trying to debug a memory leak in your Go application, and need a way to determine which type is taking the most memory I.E a sorted list of (object type, total instances, total memory).
Runtime.MemStats doesn’t give details about the type, and goprof doesn’t seem to do memory profiling.

At this moment, the currente memory allocator only keeps track of whether or not the type can
contain a pointer

0 spam comments blocked