{"id":20271930,"url":"https://github.com/point-c/wgapi","last_synced_at":"2026-04-17T09:31:50.399Z","repository":{"id":215196367,"uuid":"737911798","full_name":"point-c/wgapi","owner":"point-c","description":"wgapi makes configuring wireguard-go easier","archived":false,"fork":false,"pushed_at":"2024-01-21T06:58:48.000Z","size":437,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-11-22T19:20:39.411Z","etag":null,"topics":["generated-code","generics","golang","golang-library","templates","wireguard","wireguard-go"],"latest_commit_sha":null,"homepage":"https://point-c.github.io/wgapi/","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/point-c.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-01-01T23:50:59.000Z","updated_at":"2025-07-01T07:16:32.000Z","dependencies_parsed_at":"2024-11-14T12:45:18.039Z","dependency_job_id":"a8c75922-e0a3-47ac-a2cc-767b4f400bf8","html_url":"https://github.com/point-c/wgapi","commit_stats":null,"previous_names":["point-c/wgapi"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/point-c/wgapi","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/point-c%2Fwgapi","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/point-c%2Fwgapi/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/point-c%2Fwgapi/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/point-c%2Fwgapi/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/point-c","download_url":"https://codeload.github.com/point-c/wgapi/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/point-c%2Fwgapi/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31923100,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T09:10:15.403Z","status":"ssl_error","status_checked_at":"2026-04-17T09:10:14.455Z","response_time":62,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["generated-code","generics","golang","golang-library","templates","wireguard","wireguard-go"],"created_at":"2024-11-14T12:40:04.250Z","updated_at":"2026-04-17T09:31:50.375Z","avatar_url":"https://github.com/point-c.png","language":"Go","readme":"# wgapi\n\n[![Wireguard](https://img.shields.io/badge/wireguard-%2388171A.svg?logo=wireguard)](https://www.wireguard.com/xplatform/)\n[![Go Reference](https://img.shields.io/badge/godoc-reference-%23007d9c.svg)](https://point-c.github.io/wgapi)\n\n## Introduction\nWGAPI is a Go package designed to assist in communicating with the Wireguard userspace module. It focuses on programmatically creating, reading, and handling Wireguard configuration in a text-based format, making it easier to manage Wireguard instances programmatically.\n\nThe `wgconfig` package also provides convenient structures and functions for setting up Wireguard server and client configurations. It simplifies the process of generating configurations, managing keys, and setting up network parameters.\n\n## Features\n- Parsing and handling Wireguard configuration data.\n- Generating new private, public, and pre-shared keys.\n- Efficient and structured API communication with Wireguard.\n  \n## Installation\n\nTo use wgevents in your Go project, install it using `go get`:\n\n```bash\ngo get github.com/point-c/wgapi\n```\n\n## Usage\n\n### Generating Keys\n\n- **Generate a new private and public key pair:**\n  - Errors from `New\u003ckey\u003e` functions can only happen if `rand.Reader` causes an error.\n\n  ```go\n  private, public, err := wgapi.NewPrivatePublic()\n  if err != nil {\n      panic(err)\n  }\n  fmt.Printf(\"Private Key: %s\\nPublic Key: %s\\n\", private, public)\n  ```\n\n- **Generate private key:**\n  ```go\n  private, err := wgapi.NewPrivate()\n  if err != nil {\n      panic(err)\n  }\n  ```\n\n- **Generate preshared key:**\n  ```go\n  preshared, err := wgapi.NewPreshared()\n  if err != nil {\n      panic(err)\n  }\n  ```\n  \n- **Convert private key to public key:**\n  - An error will only happen if you try to get the public key from a preshared key\n\n  ```go\n  public, err := private.Public()\n  if err != nil {\n      panic(err)\n  }\n  ```\n  \n### Parsing Wireguard Configuration\n\n```go\n// Assuming configData is the Wireguard configuration data you have\nconfigData := \"PrivateKey=aSdFgH123456...\\nListenPort=51820\\n\"\n\n// Create a new IPCGet instance and write config data to it\nvar get wgapi.IPCGet\nget.Write([]byte(configData))\n\n// Parse and retrieve the configuration as key-value pairs\nipc, err := get.Value()\nif err != nil {\n    panic(err)\n}\n\n// Handle the parsed IPC data\nvar tx, rx uint64\nfor _, v := range ipc {\n\t// Type assertions can be used to find specific keys in the response\n\ttx, ok := v.(wgapi.TXBytes)\n\tif ok {\n        tx += uint64(tx)\n    }\n}\n```\n\n### Creating a Wireguard Configuration\n\n#### Freeform\n\n`wgapi.IPC` is a slice type. It can be configured programmatically as you see fit.\n\n```go\nr := wgapi.IPC{\n\t// config values...\n}.WGConfig()\n// r will be an io.Reader that contains a syntactically valid wireguard configuration\n```\n\n#### Config Helpers\n\n##### Server\n\n```go\ntype Server struct {\n    Private    wgapi.PrivateKey\n    ListenPort uint16      \n    Peers      []*Peer     \n}\n```\n\nWireguard's default listening port is `51820`. This can be set with:\n\n```go\nfunc (cfg *Server) DefaultListenPort()\n```\n\nPeers can be easily added:\n\n```go\npeerIP := net.IPv4(192, 168, 99, 2)\n\npreShared, err := wgapi.NewPreshared()\nif err != nil {\n    panic(err)\n}\n\nprivateKey, err := wgapi.NewPrivate()\nif err != nil {\n    panic(err)\n}\n// Use private key in client config\npublicKey, err := privateKey.Public()\n\nserverCfg.AddPeer(publicKey, preShared, peerIP)\n```\n\n##### Client\n\n```go\ntype Client struct {\n\tPrivate             wgapi.PrivateKey  \n\tPublic              wgapi.PublicKey   \n\tPreShared           wgapi.PresharedKey\n\tEndpoint            net.UDPAddr       \n\tPersistentKeepalive *uint16          \n\tAllowedIPs          []net.IPNet      \n}\n```\n\nClients will likely want to allow all IPs. This can easily be done with the provided method:\n\n```go\nfunc (cfg *Client) AllowAllIPs()\n```\n\nThe default persistent keepalive can be set with:\n\n```go\nfunc (cfg *Client) DefaultPersistentKeepAlive()\n```\n\n##### Pair Generator\n\nA generator exists to create configs quickly.\n\n```go\nendpoint, err := net.ResolveUDPAddr(\"udp\", \"endpoint address\")\nif err != nil {\n    panic(err)\n}\n\nclientIP := net.IPv4(192.168.99.2)\n\nclient, server, err := GenerateConfigPair(endpoint, clientIP)\nif err != nil {\n    panic(err)\n}\n// `client` and `server` contain valid config to connect to one another.\n// Matching keys are generated for each and defaults are filled in.\n```\n\n## Testing\n\nThe package includes tests that demonstrate its functionality. Use Go's testing tools to run the tests:\n\n```bash\ngo test ./...\n```\n\n## Godocs\n\nTo regenerate godocs:\n\n```bash\ngo generate -tags docs ./...\n```\n\n\n## Code Generation\n\nTo regenerate generated packages:\n\n```bash\ngo generate ./...\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoint-c%2Fwgapi","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpoint-c%2Fwgapi","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpoint-c%2Fwgapi/lists"}