How to check function parameters in Go
        Posted  
        
            by 
                deamon
            
        on Stack Overflow
        
        See other posts from Stack Overflow
        
            or by deamon
        
        
        
        Published on 2012-09-24T15:35:36Z
        Indexed on 
            2012/09/24
            15:37 UTC
        
        
        Read the original article
        Hit count: 366
        
Guava Preconditions allows to check method parameters in Java easily.
public void doUsefulThings(Something s, int x, int position) {
    checkNotNull(s);
    checkArgument(x >= 0, "Argument was %s but expected nonnegative", x);
    checkElementIndex(position, someList.size());
    // ...
}
These check methods raise exceptions if the conditions are not met.
Go has no exceptions but indicates errors with return values. So I wonder how an idiomatic Go version of the above code would look like.
© Stack Overflow or respective owner