-
Notifications
You must be signed in to change notification settings - Fork 562
/v2/identities.createIdentity #2952
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Labels
Feature
New feature or request
Comments
@chronark I will give it a shot |
oh okay, can I help with the v2 migration? |
we could use some help on other api endpoints, do you want to maybe start with one of the RBAC ones? like creating a permission? |
Alright, tag me on the issue once it is created |
This was referenced Mar 12, 2025
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Implement V2 Identity API Routes for Go
Background
We're migrating our API routes from the TypeScript implementation to a new Go API. The Go API will serve as V2 endpoints for our services. As part of this migration, we need to implement the identity creation functionality.
Assignment
Create a Go implementation of the existing TypeScript API route
v1_identities_createIdentity.ts
as a V2 endpoint. This should include:Reference Implementation
The existing TypeScript implementation is available in:
unkey/apps/api/src/routes/v1_identities_createIdentity.ts
unkey/apps/api/src/routes/v1_identities_createIdentity.happy.test.ts
unkey/apps/api/src/routes/v1_identities_createIdentity.error.test.ts
unkey/apps/api/src/routes/v1_identities_createIdentity.security.test.ts
The route allows creating identities with metadata and optional rate limits.
Requirements
Functional Requirements
The new v2 endpoint should support all the same parameters as the v1 endpoint:
externalId
(required): A unique identifier for the identity within your systemmeta
(optional): Metadata to attach to the identityratelimits
(optional): Rate limit configurationsAuthentication via root keys with proper RBAC checks
Response with the
identityId
of the newly created identityTechnical Requirements
The implementation should follow our Go API patterns:
zen
framework for the HTTP handlerfault
packageWrite comprehensive tests covering:
Files Structure
Create your implementation in:
Follow the pattern used in other routes like the ratelimit routes we shared with you.
Resources
Please look at these existing Go routes for reference:
unkey/go/apps/api/routes/v2_ratelimit_get_override
unkey/go/apps/api/routes/v2_ratelimit_set_override
You can also see how we structure our Go code in the various packages under
unkey/go/pkg/
.Expected Output
A complete implementation of the identity creation endpoint with supporting tests. Your code should be well-structured, properly tested, and follow our established patterns for Go API routes.
Code Generation
OpenAPI
Tool Used: oapi-codegen
How it works:
unkey/go/api/openapi.json
, which is an OpenAPI specification file.go generate ./...
which runs the command defined inunkey/go/api/generate.go
://go:generate go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen --config=config.yaml ./openapi.json
The generation is configured by
unkey/go/api/config.yaml
, which specifies:gen.go
)The result is a Go file with type definitions that match the API schema - allowing for type-safe API interactions.
Database Code Generation
Tool Used: sqlc
How it works:
SQL schemas and queries are defined in:
unkey/go/pkg/db/schema.sql
(database table definitions).sql
files inunkey/go/pkg/db/queries/
(e.g.,key_insert.sql
,workspace_find_by_id.sql
)Code generation is triggered by
go generate ./...
which runs the command defined inunkey/go/pkg/db/generate.go
://go:generate sqlc generate
The generation is configured by
unkey/go/pkg/db/sqlc.json
, which specifies:For each SQL query file, sqlc generates:
How to Use It
When API Changes:
openapi.json
go generate ./...
When Database Changes:
schema.sql
queries
directorygo generate ./...
db.Query.MethodName()
Good luck!
The text was updated successfully, but these errors were encountered: