5
0
mirror of https://github.com/wailsapp/wails.git synced 2025-05-08 00:53:33 +08:00
wails/v3/examples/services/hashes/hashes.go
Lea Anthony ef8c886b10
Ignore internal service methods when binding (#3720)
* Ignore internal service methods when binding

* Updated changelog.md
2024-09-09 08:36:19 +10:00

43 lines
816 B
Go

package hashes
import (
"context"
"crypto/md5"
"crypto/sha1"
"crypto/sha256"
"encoding/hex"
"github.com/wailsapp/wails/v3/pkg/application"
)
type Hashes struct {
MD5 string `json:"md5"`
SHA1 string `json:"sha1"`
SHA256 string `json:"sha256"`
}
func (h *Hashes) Generate(s string) Hashes {
md5Hash := md5.Sum([]byte(s))
sha1Hash := sha1.Sum([]byte(s))
sha256Hash := sha256.Sum256([]byte(s))
return Hashes{
MD5: hex.EncodeToString(md5Hash[:]),
SHA1: hex.EncodeToString(sha1Hash[:]),
SHA256: hex.EncodeToString(sha256Hash[:]),
}
}
func New() *Hashes {
return &Hashes{}
}
func (h *Hashes) OnShutdown() error { return nil }
func (h *Hashes) Name() string {
return "Hashes Service"
}
func (h *Hashes) OnStartup(_ context.Context, _ application.ServiceOptions) error {
return nil
}