Browse Source

En cours de développement

master
mls-361 10 months ago
parent
commit
9a84cc1b40
  1. 15
      .editorconfig
  2. 22
      LICENSE
  3. 10
      README.md
  4. 29
      Taskfile.yml
  5. 123
      application.go
  6. 8
      go.mod
  7. 10
      go.sum

15
.editorconfig

@ -0,0 +1,15 @@
root = true
[*]
indent_style = space
indent_size = 4
charset = utf-8
trim_trailing_whitespace = true
insert_final_newline = true
[*.go]
indent_style = tab
[*.md]
trim_trailing_whitespace = false

22
LICENSE

@ -1,9 +1,19 @@
MIT License
MIT License Copyright (c) 2021 mls-361
Copyright (c) <year> <copyright holders>
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is furnished
to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice (including the next
paragraph) shall be included in all copies or substantial portions of the
Software.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS
OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

10
README.md

@ -1,3 +1,11 @@
# application
A FAIRE.
A FAIRE.
## Licence
MIT.
---
Copyright (c) 2021 `mls-361`.

29
Taskfile.yml

@ -0,0 +1,29 @@
## https://taskfile.dev
##---------------------
version: '3'
tasks:
update:
cmds:
- go get -u forge.chapril.org/mls-361/fqdn
- go get -u forge.chapril.org/mls-361/uuid
- go mod tidy
lint:
cmds:
- golangci-lint run
test:
cmds:
- go test -cover -v ./...
default:
cmds:
- task: update
- task: lint
- task: test
git:
cmds:
- git add .
- git commit -m "En cours de développement"
- git push

123
application.go

@ -0,0 +1,123 @@
/*
------------------------------------------------------------------------------------------------------------------------
####### application ####### Copyright (c) 2021 mls-361 ############################################# MIT License #######
------------------------------------------------------------------------------------------------------------------------
*/
package application
import (
"fmt"
"os"
"strconv"
"strings"
"time"
"forge.chapril.org/mls-361/fqdn"
"forge.chapril.org/mls-361/uuid"
)
// Application AFAIRE.
type Application struct {
id uuid.UUID
name string
version string
builtAt time.Time
startedAt time.Time
debug int
host string
}
// New AFAIRE.
func New(name, version, builtAt string) *Application {
ts, err := strconv.ParseInt(builtAt, 0, 64)
if err != nil {
ts = 0
}
app := &Application{
id: uuid.New(),
name: name,
version: version,
builtAt: time.Unix(ts, 0),
startedAt: time.Now(),
}
if s, ok := app.LookupEnv("DEBUG"); ok {
if debug, err := strconv.Atoi(s); err == nil {
app.debug = debug
}
}
return app
}
// ID AFAIRE.
func (a *Application) ID() uuid.UUID {
return a.id
}
// Name AFAIRE.
func (a *Application) Name() string {
return a.name
}
// Version AFAIRE.
func (a *Application) Version() string {
return a.version
}
// BuiltAt AFAIRE.
func (a *Application) BuiltAt() time.Time {
return a.builtAt
}
// StartedAt AFAIRE.
func (a *Application) StartedAt() time.Time {
return a.startedAt
}
// Debug AFAIRE.
func (a *Application) Debug() int {
return a.debug
}
// LookupEnv AFAIRE.
func (a *Application) LookupEnv(suffix string) (string, bool) {
return os.LookupEnv(strings.ToUpper(a.name) + "_" + suffix)
}
// OnError AFAIRE.
func (a *Application) OnError(err error) error {
fmt.Fprintf( ///////////////////////////////////////////////////////////////////////////////////////////////////////
os.Stderr,
"Error: application=%s version=%s builtAt=%s >>> %s\n",
a.name,
a.version,
a.builtAt.String(),
err,
)
return err
}
// Initialize AFAIRE.
func (a *Application) Initialize() error {
fqdn, err := fqdn.FQDN()
if err != nil {
return err
}
a.host = fqdn
return nil
}
// Host AFAIRE.
func (a *Application) Host() string {
return a.host
}
/*
######################################################################################################## @(°_°)@ #######
*/

8
go.mod

@ -0,0 +1,8 @@
module forge.chapril.org/mls-361/application
go 1.16
require (
forge.chapril.org/mls-361/fqdn v0.0.0-20210412170508-6ca1a0146d63
forge.chapril.org/mls-361/uuid v0.0.0-20210411123640-49d47af267ff
)

10
go.sum

@ -0,0 +1,10 @@
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/failure v0.0.0-20210411202803-f4c2b4645ba6 h1:hCjlrpSSzJffmiTlFPWiazeuXz7L9ffqA16MK4YFZyw=
forge.chapril.org/mls-361/failure v0.0.0-20210411202803-f4c2b4645ba6/go.mod h1:DyK2Dj+C/nhpKvGiVsWEzK8mfkk140tJPdgIvUNWv9I=
forge.chapril.org/mls-361/fqdn v0.0.0-20210412170508-6ca1a0146d63 h1:HvONynegpVLNXwE+l1Gm/iW0hKQ8AR2bohJuve4X+dg=
forge.chapril.org/mls-361/fqdn v0.0.0-20210412170508-6ca1a0146d63/go.mod h1:zAW+/ApqrnmjqR4SP8FQUlq4/fRjNYdPL6P5EtTYrn0=
forge.chapril.org/mls-361/kvfmt v0.0.0-20210411202715-0e7c3e922d37 h1:6e1Y7hTJ0B8BYStiZSCdW4+v686rOpstQh2B5SWOhZU=
forge.chapril.org/mls-361/kvfmt v0.0.0-20210411202715-0e7c3e922d37/go.mod h1:bv44R0CAd8lQV4ub1hjLE3kWYwpfsW4Ro9zRnD4YOMU=
forge.chapril.org/mls-361/uuid v0.0.0-20210411123640-49d47af267ff h1:N7L3nN/9Wlck9qtIxH6gbQ9sbWtsZ048+eDEdpvD09g=
forge.chapril.org/mls-361/uuid v0.0.0-20210411123640-49d47af267ff/go.mod h1:OAYM+f6ErfC4jbruuG2crA5W7YSpr7+wEs2MrxIzR3Q=
Loading…
Cancel
Save