Repository navigation
api: migrate /api/v1 routes to Flamego - #8454
Merged
Merged
Conversation
unknwon
force-pushed
the
api-v1-flamego
branch
from
November 13, 2026 14:10
7c400bb to
55b73f7
Compare
3 of 4 tasks
unknwon
force-pushed
the
api-v1-flamego
branch
from
November 13, 2026 15:59
55b73f7 to
cfd57ec
Compare
unknwon
force-pushed
the
api-v1-flamego
branch
2 times, most recently
from
November 14, 2026 07:09
570ca6b to
e1884f9
Compare
unknwon
force-pushed
the
api-v1-flamego
branch
from
November 14, 2026 07:11
e1884f9 to
b36e7aa
Compare
unknwon
force-pushed
the
api-v1-flamego
branch
from
November 14, 2026 13:23
b36e7aa to
4214f98
Compare
unknwon
force-pushed
the
api-v1-flamego
branch
7 times, most recently
from
November 14, 2026 19:40
f872393 to
fcb8f7a
Compare
unknwon
force-pushed
the
api-v1-flamego
branch
3 times, most recently
from
November 14, 2026 21:23
92fd754 to
fe2ddfa
Compare
unknwon
force-pushed
the
api-v1-flamego
branch
from
November 14, 2026 21:47
fe2ddfa to
8ccbe25
Compare
unknwon
force-pushed
the
api-v1-flamego
branch
3 times, most recently
from
November 14, 2026 23:00
8d08831 to
11fc1b8
Compare
unknwon
force-pushed
the
api-v1-flamego
branch
4 times, most recently
from
November 15, 2026 22:45
5bf15dd to
c8f8d3a
Compare
unknwon
force-pushed
the
api-v1-flamego
branch
from
November 16, 2026 00:46
c8f8d3a to
77bf58f
Compare
unknwon
force-pushed
the
api-v1-flamego
branch
from
November 16, 2026 01:45
77bf58f to
da5e771
Compare
unknwon
force-pushed
the
api-v1-flamego
branch
2 times, most recently
from
November 16, 2026 03:07
334fafe to
9cadbd0
Compare
4 tasks done
unknwon
marked this pull request as ready for review
November 16, 2026 22:25
|
Preview deployment for your docs. Learn more about Mintlify Previews.
💡 Tip: Enable Automations to automatically generate PRs for you. |
Serve all API v1 routes from the Flamego router through the existing
Macaron bridge. Status codes and the {"message", "url"} error body are
unchanged. Request binding errors now use the same {"message", "url"}
body instead of the go-macaron/binding error array.
Requests that Macaron hands to the web handler, e.g., through Context.ServeWeb, could reach API v1 routes without the sign-in and authentication checks. API v1 now has a dedicated Flamego instance that is only reachable through its bridge. The bridge also unescapes each path segment like Macaron did, so encoded characters in static segments still match, and passes the original path so the pagination Link header keeps the trailing slash.
unknwon
force-pushed
the
api-v1-flamego
branch
from
November 16, 2026 22:40
9cadbd0 to
cc5899d
Compare
The API v1 bridge passes a copy of the request to Flamego, so the route pattern was set on the copy instead of the request the tracing handler reads, and spans were named after the full path. Also list the changed form keys of API v1 in the CHANGELOG.
Bind request bodies with the same rules and error responses as github.com/go-macaron/binding, including form keys such as u_i_d and source_i_d. Unknown routes, and raw files and archives whose reference does not resolve, respond with the web 404 page as before.
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Describe the pull request
Migrates all
/api/v1routes from Macaron to Flamego. Macaron still handles sessions, authentication (token, basic, reverse proxy), CORS and security headers, andREQUIRE_SIGNIN_VIEW, then hands the request to a dedicated Flamego instance for API v1. That instance is separate from the web handler, so requests that reach the web handler (e.g., throughServeWeb) can never run API v1 handlers without those checks.Contract kept: every API v1 response is the same as on
main, including status codes, headers, error bodies, and form keys. The two exceptions are listed below.How Macaron-specific behavior is preserved:
apiV1Bridgertrims the trailing slash and unescapes each path segment on its own, so%2Fstays inside its segment (e.g.,branches/feature%2Fx) and encoded characters in static segments still match. The original path is kept forLinkheaders.IsTokenAuthandIsBasicAuthare passed across the bridge forreqToken,reqBasicAuth, and the admin check inrepoAssignment.bindhelper mirrors go-macaron/binding: the same Content-Type dispatch (JSON, form, multipart, YAML), the samebinding:"..."tags and validation rules (throughbinding.RawValidate), the same form keys (e.g.,u_i_d,source_i_d), and the same[{"fieldNames", "classification", "message"}]error body with 415, 400, or 422.GET /api/v1/repos/{owner}/{repo}, back to the request the tracing handler reads, so spans are named after the route instead of the full path.Intentional behavior changes:
GET /repos/:owner/:repo/editorconfig/:filenameon an empty repository returns 404 instead of 500. The 500 was a nil-pointer panic.main, Macaron's static-route shortcut matched the decoded path, so parameterless routes were also reachable through an encoded slash between fixed segments (e.g.,/api%2Fv1/user,/api/v1/user%2Frepos). These now get the web 404 page, the same as such paths to parameterized routes already did.Refactors that come with the migration:
internal/context.APIContextis removed, andapiContextinapi/v1replaces it.repo.PrepareArchive..editorconfigparsing moves into the API v1 handler, its only user, andcontext.Repository.Editorconfigis removed.Context.HasErrorandContext.GetErrMsgare removed, because API v1 was their last user.Link to the issue: n/a
Checklist
Test plan
mainand this branch with-tags prod. Run both against fresh copies of the same SQLite data (users, orgs, teams, repositories including empty, private and mirror ones, issues, labels, milestones, hooks, keys).u_i_dandsource_i_dform keysAccept: application/vnd.gogs.sha,If-None-Match), editorconfig, mirror syncContent-Type,Content-Disposition,Location, CORS, security), and bodies with hosts, ports, and timestamps normalized.main.Results:
main: new access token SHAs, and the order of repositories updated within the same second./api%2Fv1/userand/api/v1/user%2Freposreturn 200 onmainand 404 here, as listed above.TestBindchecks the go-macaron/binding error bodies for 415, 400, and 422, and the snake_case form keys. It fails against the previousbind. Also rango test ./internal/route/... ./cmd/gogs/...andgolangci-lint run(0 issues).AI usage
Written by Amp (Claude), directed and reviewed by @unknwon.