Extract string conversion functions
This commit is contained in:
parent
ed50cef3cf
commit
33b8679f1c
3 changed files with 37 additions and 32 deletions
30
server.go
30
server.go
|
@ -4,8 +4,6 @@ import (
|
|||
"fmt"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
imapclient "github.com/emersion/go-imap/client"
|
||||
|
@ -96,34 +94,6 @@ func handleLogin(ectx echo.Context) error {
|
|||
return ctx.Render(http.StatusOK, "login.html", nil)
|
||||
}
|
||||
|
||||
func parseUid(s string) (uint32, error) {
|
||||
uid, err := strconv.ParseUint(s, 10, 32)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if uid == 0 {
|
||||
return 0, fmt.Errorf("UID must be non-zero")
|
||||
}
|
||||
return uint32(uid), nil
|
||||
}
|
||||
|
||||
func parsePartPath(s string) ([]int, error) {
|
||||
l := strings.Split(s, ".")
|
||||
path := make([]int, len(l))
|
||||
for i, s := range l {
|
||||
var err error
|
||||
path[i], err = strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if path[i] <= 0 {
|
||||
return nil, fmt.Errorf("part num must be strictly positive")
|
||||
}
|
||||
}
|
||||
return path, nil
|
||||
}
|
||||
|
||||
func New(imapURL string) *echo.Echo {
|
||||
e := echo.New()
|
||||
|
||||
|
|
35
strconv.go
Normal file
35
strconv.go
Normal file
|
@ -0,0 +1,35 @@
|
|||
package koushin
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func parseUid(s string) (uint32, error) {
|
||||
uid, err := strconv.ParseUint(s, 10, 32)
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
if uid == 0 {
|
||||
return 0, fmt.Errorf("UID must be non-zero")
|
||||
}
|
||||
return uint32(uid), nil
|
||||
}
|
||||
|
||||
func parsePartPath(s string) ([]int, error) {
|
||||
l := strings.Split(s, ".")
|
||||
path := make([]int, len(l))
|
||||
for i, s := range l {
|
||||
var err error
|
||||
path[i], err = strconv.Atoi(s)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if path[i] <= 0 {
|
||||
return nil, fmt.Errorf("part num must be strictly positive")
|
||||
}
|
||||
}
|
||||
return path, nil
|
||||
}
|
Loading…
Reference in a new issue