Browse Source

En cours de développement

master
mls-361 3 months ago
parent
commit
241a2ab48c
  1. 5
      Taskfile.yml
  2. 16
      cmd/main.go
  3. 2
      go.mod
  4. 4
      go.sum
  5. 25
      internal/config/config.go
  6. 72
      internal/engine/engine.go
  7. 65
      internal/supervisor/supervisor.go

5
Taskfile.yml

@ -32,4 +32,9 @@ tasks:
- task: lint
- task: test
- task: build
git:
cmds:
- git add .
- git commit -m "En cours de développement"
- git push

16
cmd/main.go

@ -10,6 +10,9 @@ import (
"os"
"forge.chapril.org/armen/armen/internal/cmdline"
"forge.chapril.org/armen/armen/internal/config"
"forge.chapril.org/armen/armen/internal/engine"
"forge.chapril.org/armen/armen/internal/supervisor"
"forge.chapril.org/mls-361/application"
)
@ -20,16 +23,17 @@ var (
func appRun() error {
app := application.New("armen", _version, _builtAt)
end, err := cmdline.Parse(app)
if err != nil {
if end, err := cmdline.Parse(app); end || err != nil {
return app.OnError(err)
}
if end {
return nil
}
config := config.New(app)
engine := engine.New(app, config)
supervisor := supervisor.New(config, engine)
return nil
return app.OnError(supervisor.Run())
}
func main() {

2
go.mod

@ -3,6 +3,6 @@ module forge.chapril.org/armen/armen
go 1.15
require (
forge.chapril.org/mls-361/application v0.0.0-20210412203029-d86c7a878731
forge.chapril.org/mls-361/application v0.0.0-20210414132623-3cc12ee64b10
forge.chapril.org/mls-361/crypto v0.0.0-20210412210122-fd3f4aac66eb
)

4
go.sum

@ -1,5 +1,5 @@
forge.chapril.org/mls-361/application v0.0.0-20210412203029-d86c7a878731 h1:eIX9CE+2WKXl8tm251W6iXlLkwtGp5SeFFcV+A5rjp0=
forge.chapril.org/mls-361/application v0.0.0-20210412203029-d86c7a878731/go.mod h1:POwqatcN6c54BNVrOlsJDSpRuSwoub8iRIruASBI0jM=
forge.chapril.org/mls-361/application v0.0.0-20210414132623-3cc12ee64b10 h1:vUnf1qBtd1/aJY0Sod5pdtVD4rAlYqWdS6E9QfhaZIM=
forge.chapril.org/mls-361/application v0.0.0-20210414132623-3cc12ee64b10/go.mod h1:POwqatcN6c54BNVrOlsJDSpRuSwoub8iRIruASBI0jM=
forge.chapril.org/mls-361/buffer v0.0.0-20210410182428-5dc7a7b2ae79 h1:Lh+y98uVFC7btl5FdxKNtokzHD2j14R4ZIgJECao6r4=
forge.chapril.org/mls-361/buffer v0.0.0-20210410182428-5dc7a7b2ae79/go.mod h1:JnOkXF+AEkQ4mv65rzW9eVLsauGzOYIUBQB0zUb5NGE=
forge.chapril.org/mls-361/crypto v0.0.0-20210412210122-fd3f4aac66eb h1:8pRlQkwpWHH/buFMBKBOJsuxXJebh/Gs4VFY641XDJc=

25
internal/config/config.go

@ -0,0 +1,25 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### config ####### Copyright (c) 2021 mls-361 ################################################## MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package config
import "forge.chapril.org/mls-361/application"
// Config AFAIRE.
type Config struct {
app *application.Application
}
// New AFAIRE.
func New(app *application.Application) *Config {
return &Config{
app: app,
}
}
/*
######################################################################################################## @(°_°)@ #######
*/

72
internal/engine/engine.go

@ -0,0 +1,72 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### engine ####### Copyright (c) 2021 mls-361 ################################################## MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package engine
import (
"sync"
"forge.chapril.org/armen/armen/internal/config"
"forge.chapril.org/mls-361/application"
)
// Engine AFAIRE.
type Engine struct {
app *application.Application
cfg *config.Config
stopCh chan struct{}
endCh chan error
swg sync.WaitGroup
}
// New AFAIRE.
func New(app *application.Application, cfg *config.Config) *Engine {
return &Engine{
app: app,
cfg: cfg,
stopCh: make(chan struct{}),
endCh: make(chan error, 1),
}
}
// EndCh AFAIRE.
func (e *Engine) EndCh() <-chan error {
return e.endCh
}
// Wait AFAIRE.
func (e *Engine) Wait() {
e.swg.Wait()
}
func (e *Engine) loop() {
defer e.swg.Done()
loop:
for {
select {
case <-e.stopCh:
break loop
}
}
e.endCh <- nil
}
// Start AFAIRE.
func (e *Engine) Start() {
e.swg.Add(1)
go e.loop() //@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
}
// Stop AFAIRE.
func (e *Engine) Stop() {
close(e.stopCh)
}
/*
######################################################################################################## @(°_°)@ #######
*/

65
internal/supervisor/supervisor.go

@ -0,0 +1,65 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### supervisor ####### Copyright (c) 2021 mls-361 ############################################## MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package supervisor
import (
"os"
"os/signal"
"syscall"
"forge.chapril.org/armen/armen/internal/config"
"forge.chapril.org/armen/armen/internal/engine"
)
// Supervisor AFAIRE.
type Supervisor struct {
config *config.Config
engine *engine.Engine
}
// New AFAIRE.
func New(c *config.Config, e *engine.Engine) *Supervisor {
return &Supervisor{
config: c,
engine: e,
}
}
func (s *Supervisor) loop() error {
endCh := make(chan os.Signal, 1)
defer close(endCh)
signal.Notify(endCh, os.Interrupt, syscall.SIGABRT, syscall.SIGQUIT, syscall.SIGTERM)
end := false
for {
select {
case err := <-s.engine.EndCh():
s.engine.Wait()
return err
case <-endCh:
if end {
break
}
s.engine.Stop()
}
}
}
// Run AFAIRE.
func (s *Supervisor) Run() error {
s.engine.Start()
return s.loop()
}
/*
######################################################################################################## @(°_°)@ #######
*/
Loading…
Cancel
Save