TwiN /go-away

Library for detecting profanities in Go

★ 299⑂ 58👁 2⑃ 132● 29▤ 38
GoMITCreated 2018-11-11
More from this author
Download: v1.8.1v1.8.1 ↓1.8.12025-10-25
+0
Daily
+0
Weekly
299
stars
58
forks
2
watchers
132
prs
29
issues
38
releases

README

!go-away

 go-away
!test




go-away is a stand-alone, lightweight library for detecting and censoring profanities in Go.

This library must remain extremely easy to use. Its original intent of not adding overhead will always remain.


 Installation
console
go get -u github.com/TwiN/go-away



 Usage
go
package main

import (
    "github.com/TwiN/go-away"
)

func main() {
    goaway.IsProfane("fuck this shit")                // returns true
    goaway.ExtractProfanity("fuck this shit")         // returns "fuck"
    goaway.Censor("fuck this shit")                   // returns " this "
    
    goaway.IsProfane("F   u   C  k th1$ $h!t")        // returns true
    goaway.ExtractProfanity("F   u   C  k th1$ $h!t") // returns "fuck"
    goaway.Censor("F   u   C  k th1$ $h!t")           // returns "         th1$ "
    
    goaway.IsProfane("@$$h073")                       // returns true
    goaway.ExtractProfanity("@$$h073")                // returns "asshole"
    goaway.Censor("@$$h073")                          // returns ""
    
    goaway.IsProfane("hello, world!")                 // returns false
    goaway.ExtractProfanity("hello, world!")          // returns ""
    goaway.Censor("hello, world!")                    // returns "hello, world!"

    buf := &bytes.Buffer{}
    detector := goaway.NewProfanityDetector()
    writer := goaway.NewWriter(buf, detector)
    writer.Write([]byte("fuck this shit"))
    writer.Flush()
    print(buf.String())                               // returns " this "  
}


Calling goaway.IsProfane(s), goaway.ExtractProfanity(s) or goaway.Censor(s) will use the default profanity detector,
but if you'd like to disable leet speak, numerical character or special character sanitization, you have to create a
ProfanityDetector instead:
go
profanityDetector := goaway.NewProfanityDetector().WithSanitizeLeetSpeak(false).WithSanitizeSpecialCharacters(false).WithSanitizeAccents(false)
profanityDetector.IsProfane("b!tch") // returns false because we're not sanitizing special characters

You can also disable the default behavior of white space sanitization like so:
go
profanityDetector := goaway.NewProfanityDetector().WithSanitizeSpaces(false)
profanityDetector.IsProfane("sh it") // returns false because we're not sanitizing white spaces

You can also require stricter matching by enabling WithExactWord:
go
profanityDetector := NewProfanityDetector().WithExactWord(true).WithSanitizeSpecialCharacters(true)
profanityDetector.IsProfane("analyst") // returns false because we match the exact word
profanityDetector.IsProfane("anal") // returns true


By default, the NewProfanityDetector constructor uses the default dictionaries for profanities, false positives and false negatives.
These dictionaries are exposed as goaway.DefaultProfanities, goaway.DefaultFalsePositives and goaway.DefaultFalseNegatives respectively.

If you need to load a different dictionary, you could create a new instance of ProfanityDetector on this way:
go
profanities  

Top issues

Latest release

v1.8.1 v1.8.1 2025-10-25
What's Changed
 fix(ci): Bump Go to 1.24.4 by @TwiN 
 chore(deps): bump golang.org/x/text from 0.29.0 to 0.30.0 by @dependabot[bot] in https://github.com/TwiN/go-away/pull/131
 chore(deps): bump codecov/codecov-action from 5.4.3 to 5.5.1 by @dependabot[bot] in https://github.com/TwiN/go-away/pull/128
 chore(deps): bump actions/setup-go from 5 to 6 by @dependabot[bot] in https://github.com/TwiN/go-away/pull/129


Full Changelog: https://github.com/TwiN/go-away/compare/v1.8.0...v1.8.1

Snapshot: 2026-11-27T22:26:53Z · Data license Apache-2.0 · JSON