Skip to content

Instantly share code, notes, and snippets.

@woat
Last active April 1, 2020 08:33
Show Gist options
  • Save woat/90448968586c01e62f3ff5f05edbfe9e to your computer and use it in GitHub Desktop.
Save woat/90448968586c01e62f3ff5f05edbfe9e to your computer and use it in GitHub Desktop.
side effect import golang
/*
WARNING: This product can expose you to chemicals including abestos,
which is known to the State of California to cause cancer and birth
defects or other reproductive harm.
For more information go to www.P65Warnings.ca.gov.
*/
package main
import (
"fmt"
"side-effect/me"
// force gofmt to respect
_ "side-effect/infect" // ordering by using line
// breaks
_ "side-effect/cure"
)
func main() {
fmt.Println(me.State) // "cured"
}
package me
import "side-effect/me"
var State = "empty"
package infect
import "side-effect/me"
// runs first
func init() {
me.State = "infected"
}
package cure
import "side-effect/me"
// runs second
func init() {
me.State = "cured"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment