Files
zeekay 1943f1c093 Hanzo Commerce
Multi-tenant commerce and billing: orders, subscriptions, invoices, plans,
usage metering and a credit ledger. One Go binary. MIT OR Apache-2.0.

Claude-Session: https://claude.ai/code/session_01SAtaDFm8VDiWrhYHNNtxMw
2026-09-23 21:52:16 -07:00

26 lines
682 B
Go

package parallel
import (
"reflect"
"github.com/hanzoai/commerce/datastore"
"github.com/hanzoai/commerce/models/mixin"
)
// Precompute a few common types
var (
datastoreType = reflect.TypeOf((*datastore.Datastore)(nil))
keyType = reflect.TypeOf((*datastore.Key)(nil)).Elem()
)
// Create a new entity instance of a given type
func newEntity(db *datastore.Datastore, entityType reflect.Type) mixin.Entity {
entity := reflect.New(entityType).Interface().(mixin.Entity)
model := mixin.BaseModel{Db: db, Entity: entity}
// Set model on entity
field := reflect.Indirect(reflect.ValueOf(entity)).FieldByName("Model")
field.Set(reflect.ValueOf(model))
return entity
}