Skip to content

gontract/gontract

Repository files navigation

Build Status Go Report Card GPL license Go Reference

gontract

gontract is a require-ensure-library for Go that provides a contract-programming framework. To enable Design by Contract (DbC), it aims to bridge the "procedural gap" in Go by providing explicit Require and Ensure checks for preconditions and postconditions in Go code.

Core Pillars

  • Contract Decoupling: Separating safety logic from business logic.
  • Safety Assertions: Provides immediate feedback upon contract violation during development.

API Reference

Function Purpose Usage
Require(predicate bool, msg string) Precondition: Verifies caller-provided input. Start of function.
Ensure(predicate bool, msg string) Postcondition: Verifies function logic/return values. Before return.

Best Practice

A very natural pattern is to put posconditions into a defer statement like so:

func myfunc(args...) {

// postcondition(s):
defer func() {

Ensure(..)
..Ensure(..)

}()


// precondtions:
Require(..)
...
Require(..)
...
//implementation
...

About

dA require-ensure-library for contract-programming with pre- and postconditions in golang

Topics

Resources

License

LGPL-3.0, GPL-3.0 licenses found

Licenses found

LGPL-3.0
COPYING.LESSER
GPL-3.0
COPYING

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors