internal/app: remove app interface
	
		
			
	
		
	
	
		
	
		
			All checks were successful
		
		
	
	
		
			
				
	
				Test / Create distribution (push) Successful in 36s
				
			
		
			
				
	
				Test / Sandbox (push) Successful in 2m6s
				
			
		
			
				
	
				Test / Hakurei (push) Successful in 3m21s
				
			
		
			
				
	
				Test / Hpkg (push) Successful in 3m47s
				
			
		
			
				
	
				Test / Sandbox (race detector) (push) Successful in 4m22s
				
			
		
			
				
	
				Test / Hakurei (race detector) (push) Successful in 5m16s
				
			
		
			
				
	
				Test / Flake checks (push) Successful in 1m36s
				
			
		
		
	
	
				
					
				
			
		
			All checks were successful
		
		
	
	Test / Create distribution (push) Successful in 36s
				
			Test / Sandbox (push) Successful in 2m6s
				
			Test / Hakurei (push) Successful in 3m21s
				
			Test / Hpkg (push) Successful in 3m47s
				
			Test / Sandbox (race detector) (push) Successful in 4m22s
				
			Test / Hakurei (race detector) (push) Successful in 5m16s
				
			Test / Flake checks (push) Successful in 1m36s
				
			It is very clear at this point that there will not be multiple implementations of App, and the internal/app package will never move out of internal due to hsu. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
		
							parent
							
								
									da0459aca1
								
							
						
					
					
						commit
						d0b6852cd7
					
				| @ -4,22 +4,8 @@ package app | |||||||
| import ( | import ( | ||||||
| 	"syscall" | 	"syscall" | ||||||
| 	"time" | 	"time" | ||||||
| 
 |  | ||||||
| 	"hakurei.app/hst" |  | ||||||
| 	"hakurei.app/internal/app/state" |  | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| type App interface { |  | ||||||
| 	// ID returns a copy of [state.ID] held by App. |  | ||||||
| 	ID() state.ID |  | ||||||
| 
 |  | ||||||
| 	// Seal determines the outcome of config as a [SealedApp]. |  | ||||||
| 	// The value of config might be overwritten and must not be used again. |  | ||||||
| 	Seal(config *hst.Config) (SealedApp, error) |  | ||||||
| 
 |  | ||||||
| 	String() string |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| type SealedApp interface { | type SealedApp interface { | ||||||
| 	// Run commits sealed system setup and starts the app process. | 	// Run commits sealed system setup and starts the app process. | ||||||
| 	Run(rs *RunState) error | 	Run(rs *RunState) error | ||||||
|  | |||||||
| @ -11,8 +11,8 @@ import ( | |||||||
| 	"hakurei.app/internal/sys" | 	"hakurei.app/internal/sys" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func New(ctx context.Context, os sys.State) (App, error) { | func New(ctx context.Context, os sys.State) (*App, error) { | ||||||
| 	a := new(app) | 	a := new(App) | ||||||
| 	a.sys = os | 	a.sys = os | ||||||
| 	a.ctx = ctx | 	a.ctx = ctx | ||||||
| 
 | 
 | ||||||
| @ -23,7 +23,7 @@ func New(ctx context.Context, os sys.State) (App, error) { | |||||||
| 	return a, err | 	return a, err | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func MustNew(ctx context.Context, os sys.State) App { | func MustNew(ctx context.Context, os sys.State) *App { | ||||||
| 	a, err := New(ctx, os) | 	a, err := New(ctx, os) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		log.Fatalf("cannot create app: %v", err) | 		log.Fatalf("cannot create app: %v", err) | ||||||
| @ -31,7 +31,7 @@ func MustNew(ctx context.Context, os sys.State) App { | |||||||
| 	return a | 	return a | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| type app struct { | type App struct { | ||||||
| 	id  *stringPair[state.ID] | 	id  *stringPair[state.ID] | ||||||
| 	sys sys.State | 	sys sys.State | ||||||
| 	ctx context.Context | 	ctx context.Context | ||||||
| @ -40,9 +40,10 @@ type app struct { | |||||||
| 	mu sync.RWMutex | 	mu sync.RWMutex | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (a *app) ID() state.ID { a.mu.RLock(); defer a.mu.RUnlock(); return a.id.unwrap() } | // ID returns a copy of [state.ID] held by App. | ||||||
|  | func (a *App) ID() state.ID { a.mu.RLock(); defer a.mu.RUnlock(); return a.id.unwrap() } | ||||||
| 
 | 
 | ||||||
| func (a *app) String() string { | func (a *App) String() string { | ||||||
| 	if a == nil { | 	if a == nil { | ||||||
| 		return "(invalid app)" | 		return "(invalid app)" | ||||||
| 	} | 	} | ||||||
| @ -60,7 +61,9 @@ func (a *app) String() string { | |||||||
| 	return fmt.Sprintf("(unsealed app %s)", a.id) | 	return fmt.Sprintf("(unsealed app %s)", a.id) | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func (a *app) Seal(config *hst.Config) (SealedApp, error) { | // Seal determines the outcome of [hst.Config] as a [SealedApp]. | ||||||
|  | // Values stored in and referred to by [hst.Config] might be overwritten and must not be used again. | ||||||
|  | func (a *App) Seal(config *hst.Config) (SealedApp, error) { | ||||||
| 	a.mu.Lock() | 	a.mu.Lock() | ||||||
| 	defer a.mu.Unlock() | 	defer a.mu.Unlock() | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -7,17 +7,16 @@ import ( | |||||||
| 	"hakurei.app/system" | 	"hakurei.app/system" | ||||||
| ) | ) | ||||||
| 
 | 
 | ||||||
| func NewWithID(id state.ID, os sys.State) App { | func NewWithID(id state.ID, os sys.State) *App { | ||||||
| 	a := new(app) | 	a := new(App) | ||||||
| 	a.id = newID(&id) | 	a.id = newID(&id) | ||||||
| 	a.sys = os | 	a.sys = os | ||||||
| 	return a | 	return a | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| func AppIParams(a App, sa SealedApp) (*system.I, *container.Params) { | func AppIParams(a *App, sa SealedApp) (*system.I, *container.Params) { | ||||||
| 	v := a.(*app) |  | ||||||
| 	seal := sa.(*outcome) | 	seal := sa.(*outcome) | ||||||
| 	if v.outcome != seal || v.id != seal.id { | 	if a.outcome != seal || a.id != seal.id { | ||||||
| 		panic("broken app/outcome link") | 		panic("broken app/outcome link") | ||||||
| 	} | 	} | ||||||
| 	return seal.sys, seal.container | 	return seal.sys, seal.container | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user