func NewSecString(str []byte) (*SecString, error) {
	ret := &SecString{Length: len(str)}
	var err error
	ret.String, err = unix.Mmap(-1, 0, ret.Length, unix.PROT_READ|unix.PROT_WRITE, unix.MAP_ANON|unix.MAP_PRIVATE)
	if err != nil {
		memset(str, 0)
		return nil, err
	}
	if err := unix.Mlock(ret.String); err != nil {
		memset(str, 0)
		unix.Munmap(ret.String)
		return nil, err
	}
	for i := 0; i < ret.Length; i++ {
		ret.String[i] = str[i]
		str[i] = 0
	}
	if err := unix.Mprotect(ret.String, unix.PROT_READ); err != nil {
		memset(str, 0)
		memset(ret.String, 0)
		unix.Munmap(ret.String)
		return nil, err
	}
	return ret, nil
}
Takes a []byte and builds a SecString out of it, wiping str in the
process.

A SecString should be destroyed when it's no longer needed to prevent memory leaks.
It is probably a good idea to defer SecString.Destroy()
package secstring
import (
	"errors"
	"fmt"
	"strings"
	"golang.org/x/sys/unix"
)
type SecString struct {
	String []byte  
	Length int     
}
func memset(s []byte, c byte) {
	for i := 0; i < len(s); i++ {
		s[i] = c
	}
}