refactor: move information values to info package
- Move the build and application information to the internal info package. - Move the user agent and redirect URI string to the internal client package.
This commit is contained in:
parent
89e53bcc9f
commit
cc5e3f0044
10 changed files with 34 additions and 36 deletions
|
@ -10,12 +10,13 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal"
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
applicationJSON string = "application/json; charset=utf-8"
|
applicationJSON string = "application/json; charset=utf-8"
|
||||||
|
redirectURI string = "urn:ietf:wg:oauth:2.0:oob"
|
||||||
|
userAgent string = "Enbas/0.0.0"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Client struct {
|
type Client struct {
|
||||||
|
@ -42,7 +43,7 @@ func NewClient(authentication config.Credentials) *Client {
|
||||||
gtsClient := Client{
|
gtsClient := Client{
|
||||||
Authentication: authentication,
|
Authentication: authentication,
|
||||||
HTTPClient: httpClient,
|
HTTPClient: httpClient,
|
||||||
UserAgent: internal.UserAgent,
|
UserAgent: userAgent,
|
||||||
Timeout: 5 * time.Second,
|
Timeout: 5 * time.Second,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -51,7 +52,7 @@ func NewClient(authentication config.Credentials) *Client {
|
||||||
|
|
||||||
func (g *Client) AuthCodeURL() string {
|
func (g *Client) AuthCodeURL() string {
|
||||||
format := "%s/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code"
|
format := "%s/oauth/authorize?client_id=%s&redirect_uri=%s&response_type=code"
|
||||||
escapedRedirectURI := url.QueryEscape(internal.RedirectURI)
|
escapedRedirectURI := url.QueryEscape(redirectURI)
|
||||||
|
|
||||||
return fmt.Sprintf(
|
return fmt.Sprintf(
|
||||||
format,
|
format,
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/info"
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/model"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -19,10 +19,10 @@ type registerRequest struct {
|
||||||
|
|
||||||
func (g *Client) Register() error {
|
func (g *Client) Register() error {
|
||||||
registerParams := registerRequest{
|
registerParams := registerRequest{
|
||||||
ClientName: internal.ApplicationName,
|
ClientName: info.ApplicationName,
|
||||||
RedirectUris: internal.RedirectURI,
|
RedirectUris: redirectURI,
|
||||||
Scopes: "read write",
|
Scopes: "read write",
|
||||||
Website: internal.ApplicationWebsite,
|
Website: info.ApplicationWebsite,
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := json.Marshal(registerParams)
|
data, err := json.Marshal(registerParams)
|
||||||
|
|
|
@ -5,8 +5,6 @@ import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type tokenRequest struct {
|
type tokenRequest struct {
|
||||||
|
@ -26,7 +24,7 @@ type tokenResponse struct {
|
||||||
|
|
||||||
func (g *Client) UpdateToken(code string) error {
|
func (g *Client) UpdateToken(code string) error {
|
||||||
tokenReq := tokenRequest{
|
tokenReq := tokenRequest{
|
||||||
RedirectURI: internal.RedirectURI,
|
RedirectURI: redirectURI,
|
||||||
ClientID: g.Authentication.ClientID,
|
ClientID: g.Authentication.ClientID,
|
||||||
ClientSecret: g.Authentication.ClientSecret,
|
ClientSecret: g.Authentication.ClientSecret,
|
||||||
GrantType: "authorization_code",
|
GrantType: "authorization_code",
|
||||||
|
|
|
@ -1,4 +1,9 @@
|
||||||
package version
|
package info
|
||||||
|
|
||||||
|
const (
|
||||||
|
ApplicationName string = "enbas"
|
||||||
|
ApplicationWebsite string = "https://codeflow.dananglin.me.uk/apollo/enbas"
|
||||||
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
BinaryVersion string //nolint:gochecknoglobals
|
BinaryVersion string //nolint:gochecknoglobals
|
|
@ -1,8 +0,0 @@
|
||||||
package internal
|
|
||||||
|
|
||||||
const (
|
|
||||||
ApplicationName = "enbas"
|
|
||||||
ApplicationWebsite = "https://codeflow.dananglin.me.uk/apollo/enbas"
|
|
||||||
RedirectURI = "urn:ietf:wg:oauth:2.0:oob"
|
|
||||||
UserAgent = "Enbas/0.0.0"
|
|
||||||
)
|
|
|
@ -4,12 +4,12 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/version"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/info"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (p Printer) PrintVersion(showFullVersion bool) {
|
func (p Printer) PrintVersion(showFullVersion bool) {
|
||||||
if !showFullVersion {
|
if !showFullVersion {
|
||||||
printToStdout("Enbas " + version.BinaryVersion + "\n")
|
printToStdout("Enbas " + info.BinaryVersion + "\n")
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,10 @@ func (p Printer) PrintVersion(showFullVersion bool) {
|
||||||
|
|
||||||
tableWriter := tabwriter.NewWriter(&builder, 0, 4, 1, ' ', 0)
|
tableWriter := tabwriter.NewWriter(&builder, 0, 4, 1, ' ', 0)
|
||||||
|
|
||||||
_, _ = tableWriter.Write([]byte(p.fieldFormat("Version:") + "\t" + version.BinaryVersion + "\n"))
|
_, _ = tableWriter.Write([]byte(p.fieldFormat("Version:") + "\t" + info.BinaryVersion + "\n"))
|
||||||
_, _ = tableWriter.Write([]byte(p.fieldFormat("Git commit:") + "\t" + version.GitCommit + "\n"))
|
_, _ = tableWriter.Write([]byte(p.fieldFormat("Git commit:") + "\t" + info.GitCommit + "\n"))
|
||||||
_, _ = tableWriter.Write([]byte(p.fieldFormat("Go version:") + "\t" + version.GoVersion + "\n"))
|
_, _ = tableWriter.Write([]byte(p.fieldFormat("Go version:") + "\t" + info.GoVersion + "\n"))
|
||||||
_, _ = tableWriter.Write([]byte(p.fieldFormat("Build date:") + "\t" + version.BuildTime + "\n"))
|
_, _ = tableWriter.Write([]byte(p.fieldFormat("Build date:") + "\t" + info.BuildTime + "\n"))
|
||||||
|
|
||||||
tableWriter.Flush()
|
tableWriter.Flush()
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,7 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"text/tabwriter"
|
"text/tabwriter"
|
||||||
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal/version"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/info"
|
||||||
)
|
)
|
||||||
|
|
||||||
func AppUsageFunc() func() {
|
func AppUsageFunc() func() {
|
||||||
|
@ -24,13 +24,13 @@ func AppUsageFunc() func() {
|
||||||
return func() {
|
return func() {
|
||||||
var builder strings.Builder
|
var builder strings.Builder
|
||||||
|
|
||||||
builder.WriteString("SUMMARY:\n enbas - A GoToSocial client for the terminal.\n\n")
|
builder.WriteString("SUMMARY:\n " + info.ApplicationName + " - A GoToSocial client for the terminal.\n\n")
|
||||||
|
|
||||||
if version.BinaryVersion != "" {
|
if info.BinaryVersion != "" {
|
||||||
builder.WriteString("VERSION:\n " + version.BinaryVersion + "\n\n")
|
builder.WriteString("VERSION:\n " + info.BinaryVersion + "\n\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
builder.WriteString("USAGE:\n enbas [flags]\n enbas [flags] [command]\n\nCOMMANDS:")
|
builder.WriteString("USAGE:\n " + info.ApplicationName + " [flags]\n " + info.ApplicationName + " [flags] [command]\n\nCOMMANDS:")
|
||||||
|
|
||||||
tableWriter := tabwriter.NewWriter(&builder, 0, 8, 0, '\t', 0)
|
tableWriter := tabwriter.NewWriter(&builder, 0, 8, 0, '\t', 0)
|
||||||
|
|
||||||
|
@ -45,7 +45,7 @@ func AppUsageFunc() func() {
|
||||||
fmt.Fprintf(&builder, "\n --%s\n %s", f.Name, f.Usage)
|
fmt.Fprintf(&builder, "\n --%s\n %s", f.Name, f.Usage)
|
||||||
})
|
})
|
||||||
|
|
||||||
builder.WriteString("\n\nUse \"enbas [command] --help\" for more information about a command.\n")
|
builder.WriteString("\n\nUse \"" + info.ApplicationName + " [command] --help\" for more information about a command.\n")
|
||||||
|
|
||||||
w := flag.CommandLine.Output()
|
w := flag.CommandLine.Output()
|
||||||
fmt.Fprint(w, builder.String())
|
fmt.Fprint(w, builder.String())
|
||||||
|
|
|
@ -4,6 +4,8 @@ import (
|
||||||
"flag"
|
"flag"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/info"
|
||||||
)
|
)
|
||||||
|
|
||||||
// ExecutorUsageFunc returns the function used to print a command's help page.
|
// ExecutorUsageFunc returns the function used to print a command's help page.
|
||||||
|
@ -14,7 +16,7 @@ func ExecutorUsageFunc(name, summary string, flagset *flag.FlagSet) func() {
|
||||||
builder.WriteString("SUMMARY:")
|
builder.WriteString("SUMMARY:")
|
||||||
builder.WriteString("\n " + name + " - " + summary)
|
builder.WriteString("\n " + name + " - " + summary)
|
||||||
builder.WriteString("\n\nUSAGE:")
|
builder.WriteString("\n\nUSAGE:")
|
||||||
builder.WriteString("\n enbas " + name)
|
builder.WriteString("\n " + info.ApplicationName + " " + name)
|
||||||
|
|
||||||
flagMap := make(map[string]string)
|
flagMap := make(map[string]string)
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@ import (
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
|
||||||
"codeflow.dananglin.me.uk/apollo/enbas/internal"
|
"codeflow.dananglin.me.uk/apollo/enbas/internal/info"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -24,7 +24,7 @@ func CalculateConfigDir(configDir string) (string, error) {
|
||||||
return "", fmt.Errorf("unable to get your default config diretory: %w", err)
|
return "", fmt.Errorf("unable to get your default config diretory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return filepath.Join(configRoot, internal.ApplicationName), nil
|
return filepath.Join(configRoot, info.ApplicationName), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func CalculateMediaCacheDir(cacheRoot, instance string) (string, error) {
|
func CalculateMediaCacheDir(cacheRoot, instance string) (string, error) {
|
||||||
|
@ -57,7 +57,7 @@ func calculateCacheDir(cacheRoot, instance string) (string, error) {
|
||||||
return "", fmt.Errorf("unable to get your default cache directory: %w", err)
|
return "", fmt.Errorf("unable to get your default cache directory: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
return filepath.Join(cacheRoot, internal.ApplicationName, fqdn), nil
|
return filepath.Join(cacheRoot, info.ApplicationName, fqdn), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func EnsureDirectory(dir string) error {
|
func EnsureDirectory(dir string) error {
|
||||||
|
|
|
@ -110,7 +110,7 @@ func Clean() error {
|
||||||
|
|
||||||
// ldflags returns the build flags.
|
// ldflags returns the build flags.
|
||||||
func ldflags() string {
|
func ldflags() string {
|
||||||
versionPackage := "codeflow.dananglin.me.uk/apollo/enbas/internal/version"
|
versionPackage := "codeflow.dananglin.me.uk/apollo/enbas/internal/info"
|
||||||
binaryVersionVar := versionPackage + "." + "BinaryVersion"
|
binaryVersionVar := versionPackage + "." + "BinaryVersion"
|
||||||
gitCommitVar := versionPackage + "." + "GitCommit"
|
gitCommitVar := versionPackage + "." + "GitCommit"
|
||||||
goVersionVar := versionPackage + "." + "GoVersion"
|
goVersionVar := versionPackage + "." + "GoVersion"
|
||||||
|
|
Loading…
Reference in a new issue