Functions / Variables of function type / Essential Go

Run Settings
LanguageGo
Language Version
Run Command
package main var isUserAdminFn func(string) bool func isUserAdminProduction(userName string) bool { // an real implementation that talks to database return false } func isUserAdminMock(userName string) bool { // a fake implementation used for tests return userName == "admin" } func isUserAdmin(userName string) bool { return isUserAdminFn(userName) } func main() { isUserAdminFn = isUserAdminProduction // in test you would use: // isUserAdminFn = isUserAdminMock }
Editor Settings
Theme
Key bindings
Full width
Lines