From ee93284cdc9290e921e8ac84b5a4c840d2d3cd7f Mon Sep 17 00:00:00 2001 From: "Alexander \"Arav\" Andreev" Date: Sun, 8 Jan 2023 18:34:35 +0400 Subject: [PATCH] Added a library usage example in README. --- README.md | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1efbb82..fbabc68 100644 --- a/README.md +++ b/README.md @@ -95,4 +95,38 @@ And if answer was correct a client gets a HTTP code 202. Or 403 otherwise. Then a server checks if CAPTCHA was solved with following request. - GET /n60f2K9JiD5c4qX9MYe90A54nT0nnJrtgfhAjfaWtBg \ No newline at end of file + GET /n60f2K9JiD5c4qX9MYe90A54nT0nnJrtgfhAjfaWtBg + +## Library usage + +A simple example using built-in dwelling CAPTCHA implementation. + +Create a new CAPTCHA: + + c := dwcaptcha.NewDwellingCaptcha(expiry) + _, id := inmemdb.New(someAdditionalDataUsedInIDGenerationUsuallyIPAddr, c) + +Get an image for a CAPTCHA: + + i := inmemdb.Image(captchaID, captchaStyle) + if i == nil { + ... // error handling + } + + jpeg.Encode(w, *i, &jpeg.Options{Quality: 20}) + +Solve a CAPTCHA: + + if ok := inmemdb.Solve(captchaID, answer); !ok { + ... // not solved + } + // solved + ... + +Check is CAPTCHA was solved: + + if ok := inmemdb.IsSolved(captchaID); !ok { + ... // not solved + } + // solved + ... \ No newline at end of file