refactor: split go-pkg
This commit is contained in:
@@ -6,10 +6,10 @@ import (
|
||||
|
||||
"go.sour.is/ev"
|
||||
"go.sour.is/ev/app/msgbus"
|
||||
"go.sour.is/ev/internal/lg"
|
||||
"go.sour.is/ev/pkg/service"
|
||||
"go.sour.is/ev/pkg/es/driver/projecter"
|
||||
"go.sour.is/ev/pkg/slice"
|
||||
"go.sour.is/ev/pkg/driver/projecter"
|
||||
"go.sour.is/pkg/lg"
|
||||
"go.sour.is/pkg/service"
|
||||
"go.sour.is/pkg/slice"
|
||||
)
|
||||
|
||||
var _ = apps.Register(50, func(ctx context.Context, svc *service.Harness) error {
|
||||
|
||||
@@ -4,13 +4,14 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"go.sour.is/pkg/env"
|
||||
"go.sour.is/pkg/lg"
|
||||
"go.sour.is/pkg/service"
|
||||
"go.sour.is/pkg/slice"
|
||||
|
||||
"go.sour.is/ev"
|
||||
"go.sour.is/ev/app/peerfinder"
|
||||
"go.sour.is/ev/internal/lg"
|
||||
"go.sour.is/ev/pkg/env"
|
||||
"go.sour.is/ev/pkg/es/driver/projecter"
|
||||
"go.sour.is/ev/pkg/service"
|
||||
"go.sour.is/ev/pkg/slice"
|
||||
"go.sour.is/ev/pkg/driver/projecter"
|
||||
)
|
||||
|
||||
var _ = apps.Register(50, func(ctx context.Context, svc *service.Harness) error {
|
||||
|
||||
@@ -11,10 +11,10 @@ import (
|
||||
|
||||
"go.sour.is/ev"
|
||||
"go.sour.is/ev/app/salty"
|
||||
"go.sour.is/ev/internal/lg"
|
||||
"go.sour.is/ev/pkg/env"
|
||||
"go.sour.is/ev/pkg/service"
|
||||
"go.sour.is/ev/pkg/slice"
|
||||
"go.sour.is/pkg/env"
|
||||
"go.sour.is/pkg/lg"
|
||||
"go.sour.is/pkg/service"
|
||||
"go.sour.is/pkg/slice"
|
||||
)
|
||||
|
||||
var _ = apps.Register(50, func(ctx context.Context, svc *service.Harness) error {
|
||||
|
||||
@@ -3,8 +3,8 @@ package main
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.sour.is/ev/internal/lg"
|
||||
"go.sour.is/ev/pkg/service"
|
||||
"go.sour.is/pkg/lg"
|
||||
"go.sour.is/pkg/service"
|
||||
)
|
||||
|
||||
var _ = apps.Register(50, func(ctx context.Context, svc *service.Harness) error {
|
||||
|
||||
@@ -7,12 +7,13 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/patrickmn/go-cache"
|
||||
|
||||
"go.sour.is/ev"
|
||||
"go.sour.is/ev/app/webfinger"
|
||||
"go.sour.is/ev/internal/lg"
|
||||
"go.sour.is/ev/pkg/env"
|
||||
"go.sour.is/ev/pkg/service"
|
||||
"go.sour.is/ev/pkg/slice"
|
||||
"go.sour.is/pkg/env"
|
||||
"go.sour.is/pkg/lg"
|
||||
"go.sour.is/pkg/service"
|
||||
"go.sour.is/pkg/slice"
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
@@ -8,8 +8,8 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
|
||||
"go.sour.is/ev/internal/lg"
|
||||
"go.sour.is/ev/pkg/service"
|
||||
"go.sour.is/pkg/lg"
|
||||
"go.sour.is/pkg/service"
|
||||
)
|
||||
|
||||
var apps service.Apps
|
||||
|
||||
@@ -3,18 +3,19 @@ package main
|
||||
import (
|
||||
"context"
|
||||
|
||||
"go.sour.is/ev"
|
||||
"go.sour.is/ev/internal/lg"
|
||||
"go.sour.is/ev/pkg/env"
|
||||
"go.sour.is/ev/pkg/es"
|
||||
diskstore "go.sour.is/ev/pkg/es/driver/disk-store"
|
||||
memstore "go.sour.is/ev/pkg/es/driver/mem-store"
|
||||
"go.sour.is/ev/pkg/es/driver/projecter"
|
||||
resolvelinks "go.sour.is/ev/pkg/es/driver/resolve-links"
|
||||
"go.sour.is/ev/pkg/es/driver/streamer"
|
||||
"go.sour.is/ev/pkg/es/event"
|
||||
"go.sour.is/ev/pkg/service"
|
||||
"go.sour.is/pkg/env"
|
||||
"go.sour.is/pkg/lg"
|
||||
"go.sour.is/pkg/service"
|
||||
"go.uber.org/multierr"
|
||||
|
||||
"go.sour.is/ev"
|
||||
diskstore "go.sour.is/ev/pkg/driver/disk-store"
|
||||
memstore "go.sour.is/ev/pkg/driver/mem-store"
|
||||
"go.sour.is/ev/pkg/driver/projecter"
|
||||
resolvelinks "go.sour.is/ev/pkg/driver/resolve-links"
|
||||
"go.sour.is/ev/pkg/driver/streamer"
|
||||
"go.sour.is/ev/pkg/es"
|
||||
"go.sour.is/ev/pkg/event"
|
||||
)
|
||||
|
||||
var _ = apps.Register(10, func(ctx context.Context, svc *service.Harness) error {
|
||||
|
||||
@@ -4,12 +4,13 @@ import (
|
||||
"context"
|
||||
"net/http"
|
||||
|
||||
"go.sour.is/pkg/gql/resolver"
|
||||
"go.sour.is/pkg/lg"
|
||||
"go.sour.is/pkg/mux"
|
||||
"go.sour.is/pkg/service"
|
||||
"go.sour.is/pkg/slice"
|
||||
|
||||
"go.sour.is/ev/app/gql"
|
||||
"go.sour.is/ev/internal/lg"
|
||||
"go.sour.is/ev/pkg/gql/resolver"
|
||||
"go.sour.is/ev/pkg/mux"
|
||||
"go.sour.is/ev/pkg/service"
|
||||
"go.sour.is/ev/pkg/slice"
|
||||
)
|
||||
|
||||
var _ = apps.Register(90, func(ctx context.Context, svc *service.Harness) error {
|
||||
|
||||
@@ -7,11 +7,12 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/rs/cors"
|
||||
"go.sour.is/ev/internal/lg"
|
||||
"go.sour.is/ev/pkg/env"
|
||||
"go.sour.is/ev/pkg/mux"
|
||||
"go.sour.is/ev/pkg/service"
|
||||
"go.sour.is/ev/pkg/slice"
|
||||
|
||||
"go.sour.is/pkg/env"
|
||||
"go.sour.is/pkg/lg"
|
||||
"go.sour.is/pkg/mux"
|
||||
"go.sour.is/pkg/service"
|
||||
"go.sour.is/pkg/slice"
|
||||
)
|
||||
|
||||
var _ = apps.Register(20, func(ctx context.Context, svc *service.Harness) error {
|
||||
|
||||
@@ -16,10 +16,10 @@ import (
|
||||
"strings"
|
||||
|
||||
"github.com/docopt/docopt-go"
|
||||
"go.sour.is/pkg/xdg"
|
||||
"gopkg.in/yaml.v3"
|
||||
|
||||
"go.sour.is/ev/app/webfinger"
|
||||
"go.sour.is/ev/cmd/webfinger-cli/xdg"
|
||||
)
|
||||
|
||||
var usage = `Webfinger CLI.
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
//go:build darwin
|
||||
// +build darwin
|
||||
|
||||
package xdg
|
||||
|
||||
func literal(name string) string {
|
||||
return "$" + name
|
||||
}
|
||||
|
||||
const (
|
||||
defaultDataHome = "~/Library/Application Support"
|
||||
defaultDataDirs = "/Library/Application Support"
|
||||
defaultConfigHome = "~/Library/Preferences"
|
||||
defaultConfigDirs = "/Library/Preferences"
|
||||
defaultCacheHome = "~/Library/Caches"
|
||||
defaultStateHome = "~/Library/Caches"
|
||||
defaultRuntime = "~/Library/Application Support"
|
||||
|
||||
defaultDesktop = "~/Desktop"
|
||||
defaultDownload = "~/Downloads"
|
||||
defaultDocuments = "~/Documents"
|
||||
defaultMusic = "~/Music"
|
||||
defaultPictures = "~/Pictures"
|
||||
defaultVideos = "~/Videos"
|
||||
defaultTemplates = "~/Templates"
|
||||
defaultPublic = "~/Public"
|
||||
|
||||
defaultApplicationDirs = "~/Applications:/Applications"
|
||||
defaultFontDirs = "~/Library/Fonts:/Library/Fonts:/System/Library/Fonts:/Network/Library/Fonts"
|
||||
)
|
||||
@@ -1,30 +0,0 @@
|
||||
//go:build linux
|
||||
// +build linux
|
||||
|
||||
package xdg
|
||||
|
||||
func literal(name string) string {
|
||||
return "$" + name
|
||||
}
|
||||
|
||||
const (
|
||||
defaultDataHome = "~/.local/share"
|
||||
defaultDataDirs = "/usr/local/share:/usr/share"
|
||||
defaultConfigHome = "~/.config"
|
||||
defaultConfigDirs = "/etc/xdg"
|
||||
defaultCacheHome = "~/.local/cache"
|
||||
defaultStateHome = "~/.local/state"
|
||||
defaultRuntime = "/run/user/$UID"
|
||||
|
||||
defaultDesktop = "~/Desktop"
|
||||
defaultDownload = "~/Downloads"
|
||||
defaultDocuments = "~/Documents"
|
||||
defaultMusic = "~/Music"
|
||||
defaultPictures = "~/Pictures"
|
||||
defaultVideos = "~/Videos"
|
||||
defaultTemplates = "~/Templates"
|
||||
defaultPublic = "~/Public"
|
||||
|
||||
defaultApplicationDirs = "~/Applications:/Applications"
|
||||
defaultFontDirs = "~/.local/share/fonts:/usr/local/share/fonts:/usr/share/fonts:~/.fonts"
|
||||
)
|
||||
@@ -1,30 +0,0 @@
|
||||
//go:build windows
|
||||
// +build windows
|
||||
|
||||
package xdg
|
||||
|
||||
func literal(name string) string {
|
||||
return "%" + name + "%"
|
||||
}
|
||||
|
||||
const (
|
||||
defaultDataHome = `%LOCALAPPDATA%`
|
||||
defaultDataDirs = `%APPDATA%\Roaming;%ProgramData%`
|
||||
defaultConfigHome = `%LOCALAPPDATA%`
|
||||
defaultConfigDirs = `%ProgramData%`
|
||||
defaultCacheHome = `%LOCALAPPDATA%\cache`
|
||||
defaultStateHome = `%LOCALAPPDATA%\state`
|
||||
defaultRuntime = `%LOCALAPPDATA%`
|
||||
|
||||
defaultDesktop = `%USERPROFILE%\Desktop`
|
||||
defaultDownload = `%USERPROFILE%\Downloads`
|
||||
defaultDocuments = `%USERPROFILE%\Documents`
|
||||
defaultMusic = `%USERPROFILE%\Music`
|
||||
defaultPictures = `%USERPROFILE%\Pictures`
|
||||
defaultVideos = `%USERPROFILE%\Videos`
|
||||
defaultTemplates = `%USERPROFILE%\Templates`
|
||||
defaultPublic = `%USERPROFILE%\Public`
|
||||
|
||||
defaultApplicationDirs = `%APPDATA%\Roaming\Microsoft\Windows\Start Menu\Programs`
|
||||
defaultFontDirs = `%windir%\Fonts;%LOCALAPPDATA%\Microsoft\Windows\Fonts`
|
||||
)
|
||||
@@ -1,52 +0,0 @@
|
||||
package xdg
|
||||
|
||||
import (
|
||||
"os"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var (
|
||||
EnvDataHome = setENV("XDG_DATA_HOME", defaultDataHome)
|
||||
EnvDataDirs = setENV("XDG_DATA_DIRS", defaultDataDirs)
|
||||
EnvConfigHome = setENV("XDG_CONFIG_HOME", defaultConfigHome)
|
||||
EnvConfigDirs = setENV("XDG_CONFIG_DIRS", defaultConfigDirs)
|
||||
EnvCacheHome = setENV("XDG_CACHE_HOME", defaultCacheHome)
|
||||
EnvStateHome = setENV("XDG_STATE_HOME", defaultStateHome)
|
||||
EnvRuntime = setENV("XDG_RUNTIME_DIR", defaultRuntime)
|
||||
EnvDesktopDir = setENV("XDG_DESKTOP_DIR", defaultDesktop)
|
||||
EnvDownloadDir = setENV("XDG_DOWNLOAD_DIR", defaultDownload)
|
||||
EnvDocumentsDir = setENV("XDG_DOCUMENTS_DIR", defaultDocuments)
|
||||
EnvMusicDir = setENV("XDG_MUSIC_DIR", defaultMusic)
|
||||
EnvPicturesDir = setENV("XDG_PICTURES_DIR", defaultPictures)
|
||||
EnvVideosDir = setENV("XDG_VIDEOS_DIR", defaultVideos)
|
||||
EnvTemplatesDir = setENV("XDG_TEMPLATES_DIR", defaultTemplates)
|
||||
EnvPublicShareDir = setENV("XDG_PUBLICSHARE_DIR", defaultPublic)
|
||||
EnvApplicationsDir = setENV("XDG_APPLICATIONS_DIR", defaultApplicationDirs)
|
||||
EnvFontsDir = setENV("XDG_FONTS_DIR", defaultFontDirs)
|
||||
)
|
||||
|
||||
func setENV(name, value string) string {
|
||||
if _, ok := os.LookupEnv(name); !ok {
|
||||
os.Setenv(name, value)
|
||||
}
|
||||
return literal(name)
|
||||
}
|
||||
func Get(base, suffix string) string {
|
||||
paths := strings.Split(os.ExpandEnv(base), string(os.PathListSeparator))
|
||||
for i, path := range paths {
|
||||
if strings.HasPrefix(path, "~") {
|
||||
path = strings.Replace(path, "~", getHome(), 1)
|
||||
}
|
||||
paths[i] = os.ExpandEnv(filepath.Join(path, suffix))
|
||||
}
|
||||
return strings.Join(paths, string(os.PathListSeparator))
|
||||
}
|
||||
|
||||
func getHome() string {
|
||||
home, err := os.UserHomeDir()
|
||||
if err != nil {
|
||||
return "."
|
||||
}
|
||||
return home
|
||||
}
|
||||
Reference in New Issue
Block a user