forked from layeh/radius
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes layeh#37
- Loading branch information
Tim Cooper
committed
Sep 26, 2018
1 parent
639444c
commit 7f0e5b5
Showing
3 changed files
with
84 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package radius_test | ||
|
||
import ( | ||
"log" | ||
|
||
"layeh.com/radius" | ||
. "layeh.com/radius/rfc2865" | ||
) | ||
|
||
var ( | ||
Username = "tim" | ||
Password = "12345" | ||
) | ||
|
||
func Example_packetServer() { | ||
handler := func(w radius.ResponseWriter, r *radius.Request) { | ||
username := UserName_GetString(r.Packet) | ||
password := UserPassword_GetString(r.Packet) | ||
|
||
var code radius.Code | ||
if username == Username && password == Password { | ||
code = radius.CodeAccessAccept | ||
} else { | ||
code = radius.CodeAccessReject | ||
} | ||
log.Printf("Writing %v to %v", code, r.RemoteAddr) | ||
w.Write(r.Response(code)) | ||
} | ||
|
||
server := radius.PacketServer{ | ||
Handler: radius.HandlerFunc(handler), | ||
SecretSource: radius.StaticSecretSource([]byte(`secret`)), | ||
} | ||
|
||
log.Printf("Starting server on :1812") | ||
if err := server.ListenAndServe(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |