package config type RuntimeConfig struct { Name string Extension string MIMEType string } var Runtimes = []RuntimeConfig{ {Name: "bash", Extension: ".sh", MIMEType: "text/x-shellscript"}, {Name: "zsh", Extension: ".zsh", MIMEType: "text/x-shellscript"}, {Name: "sh", Extension: ".sh", MIMEType: "text/x-shellscript"}, {Name: "fish", Extension: ".fish", MIMEType: "text/x-shellscript"}, {Name: "python3", Extension: ".py", MIMEType: "text/x-python"}, {Name: "node", Extension: ".js", MIMEType: "text/javascript"}, {Name: "ruby", Extension: ".rb", MIMEType: "text/x-ruby"}, {Name: "php", Extension: ".php", MIMEType: "text/x-php"}, } var RuntimeMap map[string]RuntimeConfig func init() { RuntimeMap = make(map[string]RuntimeConfig, len(Runtimes)) for _, rt := range Runtimes { RuntimeMap[rt.Name] = rt } } func IsValidRuntime(name string) bool { _, ok := RuntimeMap[name] return ok } func GetRuntime(name string) (RuntimeConfig, bool) { rt, ok := RuntimeMap[name] return rt, ok } func IsShellRuntime(name string) bool { switch name { case "bash", "zsh", "sh", "fish": return true } return false } func GetSourceCommand(url, runtime string) string { switch runtime { case "bash", "zsh": return "source <(curl " + url + ")" case "sh": return ". <(curl " + url + ")" case "fish": return "curl " + url + " | source" default: return "" } }