mirror of
https://github.com/hanzoai/commerce.git
synced 2026-10-30 15:08:42 +00:00
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
26 lines
682 B
Go
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
|
|
}
|