Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings
This repository was archived by the owner on Aug 30, 2024. It is now read-only.
/coder-v1-cliPublic archive

refactor: use constants for OSs#448

Merged
greyscaled merged 1 commit intomainfromvapurrmaid/rfr-os-consts
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletionsinternal/cmd/configssh.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -160,7 +160,7 @@ func binPath() (string, error) {
// Bash and OpenSSH for Windows (used by Powershell and VS Code) to function
// correctly. Check if the current executable is in $PATH, and warn the user
// if it isn't.
if runtime.GOOS =="windows" {
if runtime.GOOS ==goosWindows {
binName := filepath.Base(exePath)

// We use safeexec instead of os/exec because os/exec returns paths in
Expand DownExpand Up@@ -268,7 +268,7 @@ func makeSSHConfig(binPath, workspaceName, privateKeyFilepath string, additional
fmt.Sprintf("IdentityFile=%q", privateKeyFilepath),
)

if runtime.GOOS =="linux" || runtime.GOOS =="darwin" {
if runtime.GOOS ==goosLinux || runtime.GOOS ==goosDarwin {
options = append(options,
"ControlMaster auto",
"ControlPath ~/.ssh/.connection-%r@%h:%p",
Expand Down
3 changes: 2 additions & 1 deletioninternal/cmd/update.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -36,6 +36,7 @@ import (
const (
goosWindows = "windows"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It's unfortunate that Go doesn't seem to offer these constants in their code anywhere. It looks like Go themselves use hardcoded string comparisons everywhere:https://sourcegraph.com/search?q=context:global+repo:%5Egithub%5C.com/golang/go%24+%22windows%22&patternType=literal -- given that, maybe it's okay for us to do that too?

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Personally I think that doesn't sit well unless at least a type (like TS union of strings as a type alias) is defined. That feels a bit like walking on quicksand.

I don't know their reason, but I think it's reasonable we reach for them in our own domain model/application code base. I'd expect there to be some concept of a constant, enumeration or type in other languages when approaching a similar problem. Go sometimes makes odd choices IMO :P

goosLinux = "linux"
goosDarwin = "darwin"
apiPrivateVersion = "/api/private/version"
)

Expand DownExpand Up@@ -181,7 +182,7 @@ func (u *updater) Run(ctx context.Context, force bool, coderURLArg string, versi
// TODO: validate the checksum of the downloaded file. GitHub does not currently provide this information
// and we do not generate them yet.
var updatedBinaryName string
if u.osF() =="windows" {
if u.osF() ==goosWindows {
updatedBinaryName = "coder.exe"
} else {
updatedBinaryName = "coder"
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp