8000 serpent/env.go at v0.10.0 · coder/serpent · GitHub
[go: up one dir, main page]

Skip to content
{"payload":{"allShortcutsEnabled":false,"fileTree":{"":{"items":[{"name":".github","path":".github","contentType":"directory"},{"name":"completion","path":"completion","contentType":"directory"},{"name":"example","path":"example","contentType":"directory"},{"name":".golangci.yaml","path":".golangci.yaml","contentType":"file"},{"name":"LICENSE","path":"LICENSE","contentType":"file"},{"name":"Makefile","path":"Makefile","contentType":"file"},{"name":"README.md","path":"README.md","contentType":"file"},{"name":"command.go","path":"command.go","contentType":"file"},{"name":"command_test.go","path":"command_test.go","contentType":"file"},{"name":"completion.go","path":"completion.go","contentType":"file"},{"name":"completion_test.go","path":"completion_test.go","contentType":"file"},{"name":"env.go","path":"env.go","contentType":"file"},{"name":"env_test.go","path":"env_test.go","contentType":"file"},{"name":"go.mod","path":"go.mod","contentType":"file"},{"name":"go.sum","path":"go.sum","contentType":"file"},{"name":"help.go","path":"help.go","contentType":"file"},{"name":"help.tpl","path":"help.tpl","contentType":"file"},{"name":"net.go","path":"net.go","contentType":"file"},{"name":"option.go","path":"option.go","contentType":"file"},{"name":"option_test.go","path":"option_test.go","contentType":"file"},{"name":"serpent.go","path":"serpent.go","contentType":"file"},{"name":"values.go","path":"values.go","contentType":"file"},{"name":"yaml.go","path":"yaml.go","contentType":"file"},{"name":"yaml_test.go","path":"yaml_test.go","contentType":"file"}],"totalCount":24}},"fileTreeProcessingTime":2.6580470000000003,"foldersToFetch":[],"incompleteFileTree":false,"repo":{"id":761336034,"defaultBranch":"main","name":"serpent","ownerLogin":"coder","currentUserCanPush":false,"isFork":false,"isEmpty":false,"createdAt":"2024-02-21T17:19:10.000Z","ownerAvatar":"https://avatars.githubusercontent.com/u/95932066?v=4","public":true,"private":false,"isOrgOwned":true},"codeLineWrapEnabled":false,"symbolsExpanded":false,"treeExpanded":true,"refInfo":{"name":"v0.10.0","listCacheKey":"v0:1749764049.0","canEdit":false,"refType":"tag","currentOid":"5f3d052f196dcb377878a44582f81d334b9166a3"},"path":"env.go","currentUser":null,"blob":{"rawLines":["package serpent","","import \"strings\"","","// name returns the name of the environment variable.","func envName(line string) string {","\treturn strings.ToUpper(","\t\tstrings.SplitN(line, \"=\", 2)[0],","\t)","}","","// value returns the value of the environment variable.","func envValue(line string) string {","\ttokens := strings.SplitN(line, \"=\", 2)","\tif len(tokens) \u003c 2 {","\t\treturn \"\"","\t}","\treturn tokens[1]","}","","// Var represents a single environment variable of form","// NAME=VALUE.","type EnvVar struct {","\tName string","\tValue string","}","","type Environ []EnvVar","","func (e Environ) ToOS() []string {","\tvar env []string","\tfor _, v := range e {","\t\tenv = append(env, v.Name+\"=\"+v.Value)","\t}","\treturn env","}","","func (e Environ) Lookup(name string) (string, bool) {","\tfor _, v := range e {","\t\tif v.Name == name {","\t\t\treturn v.Value, true","\t\t}","\t}","\treturn \"\", false","}","","func (e Environ) Get(name string) string {","\tv, _ := e.Lookup(name)","\treturn v","}","","func (e *Environ) Set(name, value string) {","\tfor i, v := range *e {","\t\tif v.Name == name {","\t\t\t(*e)[i].Value = value","\t\t\treturn","\t\t}","\t}","\t*e = append(*e, EnvVar{Name: name, Value: value})","}","","// ParseEnviron returns all environment variables starting with","// prefix without said prefix.","func ParseEnviron(environ []string, prefix string) Environ {","\tvar filtered []EnvVar","\tfor _, line := range environ {","\t\tname := envName(line)","\t\tif strings.HasPrefix(name, prefix) {","\t\t\tfiltered = append(filtered, EnvVar{","\t\t\t\tName: strings.TrimPrefix(name, prefix),","\t\t\t\tValue: envValue(line),","\t\t\t})","\t\t}","\t}","\treturn filtered","}"],"stylingDirectives":null,"colorizedLines":null,"csv":null,"csvError":null,"dependabotInfo":{"showConfigurationBanner":false,"configFilePath":null,"networkDependabotPath":"/coder/serpent/network/updates","dismissConfigurationNoticePath":"/settings/dismiss-notice/dependabot_configuration_notice","configurationNoticeDismissed":null},"displayName":"env.go","displayUrl":"https://github.com/coder/serpent/blob/v0.10.0/env.go?raw=true","headerInfo":{"blobSize":"1.46 KB","deleteTooltip":"You must be signed in to make or propose changes","editTooltip":"You must be signed in to make or propose changes","ghDesktopPath":null,"isGitLfs":false,"onBranch":false,"shortPath":"a77f551","siteNavLoginPath":"/login?return_to=https%3A%2F%2Fgithub.com%2Fcoder%2Fserpent%2Fblob%2Fv0.10.0%2Fenv.go","isCSV":false,"isRichtext":false,"toc":null,"lineInfo":{"truncatedLoc":"76","truncatedSloc":"66"},"mode":"file"},"image":false,"isCodeownersFile":null,"isPlain":false,"isValidLegacyIssueTemplate":false,"issueTemplate":null,"discussionTemplate":null,"language":"Go","languageID":132,"large":false,"planSupportInfo":{"repoIsFork":null,"repoOwnedByCurrentUser":null,"requestFullPath":"/coder/serpent/blob/v0.10.0/env.go","showFreeOrgGatedFeatureMessage":null,"showPlanSupportBanner":null,"upgradeDataAttributes":null,"upgradePath":null},"publishBannersInfo":{"dismissActionNoticePath":"/settings/dismiss-notice/publish_action_from_dockerfile","releasePath":"/coder/serpent/releases/new?marketplace=true","showPublishActionBanner":false},"rawBlobUrl":"https://github.com/coder/serpent/raw/refs/tags/v0.10.0/env.go","renderImageOrRaw":false,"richText":null,"renderedFileInfo":null,"shortPath":null,"symbolsEnabled":true,"tabSize":8,"topBannersInfo":{"overridingGlobalFundingFile":false,"globalPreferredFundingPath":null,"showInvalidCitationWarning":false,"citationHelpUrl":"https://docs.github.com/github/creating-cloning-and-archiving-repositories/creating-a-repository-on-github/about-citation-files","actionsOnboardingTip":null},"truncated":false,"viewable":true,"workflowRedirectUrl":null,"symbols":null},"copilotInfo":null,"copilotAccessAllowed":false,"modelsAccessAllowed":false,"modelsRepoIntegrationEnabled":false,"isMarketplaceEnabled":true,"csrf_tokens":{"/coder/serpent/branches":{"post":"d6fdLKpx67scB8lBu8RucSrUHrM0LqEPnnoLSFbaIIi5RvVxZjaQgS_uiOGrqEa9WZ79XfT4FfGKPwW1Yzn68Q"},"/repos/preferences":{"post":"dUdDl7NXLGkpa8PSHgbvEnNJETRx9cVUqlSA2gZRbe24SUhfczIIt-BWu1udbvIkKI7cyPu9niPFkGAe4zZjUg"}}},"title":"serpent/env.go at v0.10.0 · coder/serpent","appPayload":{"helpUrl":"https://docs.github.com","findFileWorkerPath":"/assets-cdn/worker/find-file-worker-263cab1760dd.js","findInFileWorkerPath":"/assets-cdn/worker/find-in-file-worker-0b6f8702959e.js","githubDevUrl":null,"enabled_features":{"code_nav_ui_events":false,"react_blob_overlay":false,"accessible_code_button":true}}}
0