Corrections diverses : collection, datetime, ini
This commit is contained in:
parent
c473e663e8
commit
fc9b29b7f3
|
@ -113,7 +113,7 @@ func ContainsAll[T comparable, S ~[]T](s S, in ...T) bool {
|
|||
}
|
||||
|
||||
// Maps retourne un slice à partir d’un autre slice en appliquant une fonction de transformation pour chaque valeur.
|
||||
func Maps[T1, T2 any, S1 ~[]T1, S2 ~[]T2](in S1, f func(T1) T2) (out S2) {
|
||||
func Maps[T1, T2 any, S1 ~[]T1, S2 []T2](in S1, f func(T1) T2) (out S2) {
|
||||
out = make(S2, len(in))
|
||||
|
||||
for i, e := range in {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package datetime
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
|
@ -178,7 +179,10 @@ func (dt datetime) f(f string, l *time.Location) string {
|
|||
}
|
||||
return formatT(dt.t(l), f)
|
||||
}
|
||||
func (dt datetime) str(l *time.Location) string { return dt.f("Y-m-d", l) }
|
||||
func (dt datetime) str(l *time.Location) string {
|
||||
ft, fc := "y-m-d", formatP[dt.p()]
|
||||
return dt.f(fmt.Sprintf("%s %s", ft, fc), l)
|
||||
}
|
||||
|
||||
// DateTime représente une indication de temps (date + heure).
|
||||
type DateTime struct {
|
||||
|
|
40
ini/ini.go
40
ini/ini.go
|
@ -185,19 +185,24 @@ func (c *Setting) Read(r io.Reader) {
|
|||
}
|
||||
|
||||
// Write écrit la configuration dans le descripteur de sortie.
|
||||
func (c *Setting) Write(w io.Writer) error {
|
||||
func (c *Setting) Write(w io.Writer) (out Option[error]) {
|
||||
for k, v := range c.m {
|
||||
l := c.t[c.i[k]]
|
||||
i := strings.Index(l, "=")
|
||||
c.t[c.i[k]] = l[:i+1] + " " + v
|
||||
}
|
||||
|
||||
buf := bufio.NewWriter(w)
|
||||
for _, l := range c.t {
|
||||
if _, err := buf.WriteString(l + "\n"); err != nil {
|
||||
return err
|
||||
return Some(err)
|
||||
}
|
||||
}
|
||||
return buf.Flush()
|
||||
|
||||
if err := buf.Flush(); err != nil {
|
||||
out = Some(err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// IniFile représente un fichier de configuration.
|
||||
|
@ -219,22 +224,25 @@ func NewFile(template, filepath string) *IniFile {
|
|||
}
|
||||
|
||||
// Load charge la configuration
|
||||
func (cf *IniFile) Load() error {
|
||||
f, err := os.Open(cf.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
func (cf *IniFile) Load() (out Option[error]) {
|
||||
if f, err := os.Open(cf.Path); err == nil {
|
||||
defer f.Close()
|
||||
cf.Setting.Read(f)
|
||||
} else {
|
||||
out = Some(err)
|
||||
}
|
||||
defer f.Close()
|
||||
cf.Setting.Read(f)
|
||||
return nil
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// Save enregistre la configuration sur le disque.
|
||||
func (cf *IniFile) Save() error {
|
||||
f, err := os.Create(cf.Path)
|
||||
if err != nil {
|
||||
return err
|
||||
func (cf *IniFile) Save() (out Option[error]) {
|
||||
if f, err := os.Create(cf.Path); err == nil {
|
||||
defer f.Close()
|
||||
out = cf.Setting.Write(f)
|
||||
} else {
|
||||
out = Some(err)
|
||||
}
|
||||
defer f.Close()
|
||||
return cf.Setting.Write(f)
|
||||
|
||||
return
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue