func NewWithOptions(
	profileType string,
	startProfilingFunc StartProfilingFunc,
) (ProfilingService, error) {
	err := validateType(profileType)
	if err != nil {
		return nil, err
	}
	return &perfProfile{
		profileOptions: profileOptionsForType(profileType),
		startProfiling: startProfilingFunc,
	}, nil
}
NewWithOptions returns a new performance profile of the specified type
with the ability to pass in the implementing profile interface..
package profile
import (
	"fmt"
	"github.com/pkg/profile"
)
type ProfilingService interface {
	Start()
	Stop()
}
type StartProfilingFunc func(...func(*profile.Profile)) interface{ Stop() }
func (pp *perfProfile) Start() {
	pp.stopper = pp.startProfiling(pp.profileOptions...)
}
func (pp *perfProfile) Stop() {
	pp.stopper.Stop()
}
type perfProfile struct {
	profileOptions []func(*profile.Profile)
	startProfiling StartProfilingFunc
	stopper        interface{ Stop() }
}
var validTypes = []string{"cpu", "memory"}
func isValidType(profileType string) bool {
	for _, curType := range validTypes {
		if curType == profileType {
			return true
		}
	}
	return false
}
func validateType(profileType string) error {
	if !isValidType(profileType) {
		return fmt.Errorf(
			"Invalid profile type: '%s'.  Valid types are: %v",
			profileType,
			validTypes,
		)
	}
	return nil
}
func profileOptionsForType(profileType string) []func(*profile.Profile) {
	switch profileType {
	case "cpu":
		return []func(*profile.Profile){profile.CPUProfile, profile.NoShutdownHook}
	case "memory":
		return []func(*profile.Profile){profile.MemProfile, profile.NoShutdownHook}
	}
	return []func(*profile.Profile){}
}
func New(profileType string) (ProfilingService, error) {
	return NewWithOptions(profileType, profile.Start)
}