Jobs & Workflows
https://armen.surge.sh
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
2.3 KiB
109 lines
2.3 KiB
/* |
|
------------------------------------------------------------------------------------------------------------------------ |
|
####### components ####### Copyright (c) 2021 mls-361 ############################################## MIT License ####### |
|
------------------------------------------------------------------------------------------------------------------------ |
|
*/ |
|
|
|
package components |
|
|
|
import ( |
|
"net/http" |
|
"time" |
|
|
|
"forge.chapril.org/armen/jw" |
|
"forge.chapril.org/mls-361/jsonapi" |
|
"forge.chapril.org/mls-361/logger" |
|
|
|
"forge.chapril.org/armen/armen/internal/config/data" |
|
) |
|
|
|
// Application AFAIRE. |
|
type Application interface { |
|
ID() string |
|
Name() string |
|
Version() string |
|
BuiltAt() time.Time |
|
StartedAt() time.Time |
|
Debug() int |
|
LookupEnv(suffix string) (string, bool) |
|
Host() string |
|
} |
|
|
|
// Config AFAIRE. |
|
type Config interface { |
|
Data() *data.Data |
|
Logger() *data.Logger |
|
Server() *data.Server |
|
Storage() *data.Storage |
|
} |
|
|
|
// Crypto AFAIRE. |
|
type Crypto interface { |
|
DecryptString(text string) (string, error) |
|
EncryptString(text string) (string, error) |
|
} |
|
|
|
// Logger AFAIRE. |
|
type Logger interface { |
|
logger.Logger |
|
} |
|
|
|
// Model AFAIRE. |
|
type Model interface { |
|
jw.Model |
|
} |
|
|
|
// Router AFAIRE. |
|
type Router interface { |
|
Handler() http.Handler |
|
Get(path string, handler http.Handler) |
|
ServeFiles(path string, root http.FileSystem) |
|
GetJSON(path string, handler jsonapi.Handler) |
|
PostJSON(path string, handler jsonapi.Handler) |
|
} |
|
|
|
// Server AFAIRE. |
|
type Server interface { |
|
Run() error |
|
Stop() |
|
} |
|
|
|
// Storage AFAIRE. |
|
type Storage interface { |
|
jw.Storage |
|
} |
|
|
|
// Components AFAIRE. |
|
type Components struct { |
|
Application Application |
|
Config Config |
|
Crypto Crypto |
|
Logger Logger |
|
Model Model |
|
Router Router |
|
Server Server |
|
Storage Storage |
|
} |
|
|
|
// New AFAIRE. |
|
func New(app Application) *Components { |
|
return &Components{ |
|
Application: app, |
|
} |
|
} |
|
|
|
// Shutdown AFAIRE. |
|
func (ccs *Components) Shutdown() { |
|
if ccs.Logger != nil { |
|
ccs.Logger.Info( //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: |
|
"END", |
|
"uptime", time.Since(ccs.Application.StartedAt()).Round(time.Second).String(), |
|
) |
|
|
|
_ = ccs.Logger.Close() |
|
} |
|
} |
|
|
|
/* |
|
######################################################################################################## @(°_°)@ ####### |
|
*/
|
|
|