shithub: libtroll

ref: 7979dfca14134208fe237097f44a7a080e42b62f
dir: /libtroll.go/

View raw version
package libtroll

import (
	"fmt"
	"os"
	"strconv"
	"time"

	"shithub.us/hexyl/libtroll/utils"
)

type Type int64

type Program struct {
	name    string
	typ     Type
	out     os.File
	backend Backend
}

func (p *Program) Init(b Backend) {
	timestamp := strconv.FormatInt(time.Now().UTC().UnixNano(), 10)
	tmp := fmt.Sprintf("%s-%s.src", p.name, timestamp)
	f, err := os.CreateTemp("", tmp)
	utils.Check(err)
	p.out = *f
	p.backend = b
	defer os.Remove(f.Name())
}

func New(name string, typ Type) Program {
	tmpnew := Program{
		name: name,
		typ:  typ,
	}

	return tmpnew
}