gin | HTTP web framework written in Go | Web Framework library

 by   gin-gonic Go Version: v1.9.1 License: MIT

kandi X-RAY | gin Summary

kandi X-RAY | gin Summary

gin is a Go library typically used in Server, Web Framework, Framework applications. gin has no bugs, it has no vulnerabilities, it has a Permissive License and it has medium support. You can download it from GitHub.

Gin is a web framework written in Go (Golang). It features a martini-like API with performance that is up to 40 times faster thanks to httprouter. If you need performance and good productivity, you will love Gin.

            kandi-support Support

              gin has a medium active ecosystem.
              It has 69404 star(s) with 7523 fork(s). There are 1367 watchers for this library.
              It had no major release in the last 12 months.
              There are 519 open issues and 1526 have been closed. On average issues are closed in 160 days. There are 175 open pull requests and 0 closed requests.
              It has a neutral sentiment in the developer community.
              The latest version of gin is v1.9.1

            kandi-Quality Quality

              gin has 0 bugs and 0 code smells.

            kandi-Security Security

              gin has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              gin code analysis shows 0 unresolved vulnerabilities.
              There are 0 security hotspots that need review.

            kandi-License License

              gin is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              gin releases are available to install and integrate.
              Installation instructions, examples and code snippets are available.
              It has 12776 lines of code, 933 functions and 85 files.
              It has medium code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi's functional review helps you automatically verify the functionalities of the libraries and avoid rework.
            Currently covering the most popular Java, JavaScript and Python libraries. See a Sample of gin
            Get all kandi verified functions for this library.

            gin Key Features

            No Key Features are available at this moment for gin.

            gin Examples and Code Snippets

            No Code Snippets are available at this moment for gin.

            Community Discussions


            Go: How to send a File from AWS S3 via GIN-Router as binary stream to the browser?
            Asked 2022-Apr-02 at 15:42

            How can I send a file, that I've got received from S3, to Gin as binary response?

            Lets say, I have the following code to obtain an image from S3 bucket:



            Answered 2022-Apr-02 at 15:42

            You're almost done:

            Instead of ctx.Write use this one:



            Query on json / jsonb column super slow. Can I use an index?
            Asked 2022-Mar-28 at 11:01

            I am trying to speed up the querying of some json data stored inside a PostgreSQL database. I inherited an application that queries a PostgreSQL table called data with a field called value where value is blob of json of type jsonb.

            It is about 300 rows but takes 12 seconds to select this data from the 5 json elements. The json blobs are a bit large but the data I need is all in the top level of the json nesting if that helps.

            I tried adding an index of CREATE INDEX idx_tbl_data ON data USING gin (value); but that didn't help. Is there a different index I should be using? The long term vision is to re-write the application to move that data out of the json but that is something is at least 30-40 man days of work due to complexity in other parts of the application so I am looking to see if I can make this faster in short term.

            Not sure if it helps but the underlying data that makes up this result set doesn't change often. It's the data that is further down in the json blob that often changes.



            Answered 2022-Feb-12 at 12:47

            Like a_horse already advised (and you mentioned yourself), the proper fix is to extract those attributes to separate columns, normalizing your design to some extent.

            Can an index help?

            Sadly, no (as of Postgres 14).

            It could work in theory. Since your values are big, an expression index with just some small attributes can be picked up by Postgres in an index-only scan, even when retrieving all rows (where it otherwise would ignore indexes).

            The manual:

            However, PostgreSQL's planner is currently not very smart about such cases. It considers a query to be potentially executable by index-only scan only when all columns needed by the query are available from the index.

            So you would have to include value itself in the index, even if just as INCLUDE column - totally spoiling the whole idea. No go.

            You probably can still do something in the short term. Two crucial quotes:

            I am looking to see if I can make this faster in short term

            The json blobs are a bit large

            Data type

            Drop the cast to json from the query. Casting every time adds pointless cost.


            One major cost factor will be compression. Postgres has to "de-toast" the whole large column, just to extract some small attributes. Since Postgres 14, you can switch the compression algorithm (if support is enabled in your version!). The default is dictated by the config setting default_toast_compression, which is set to pglz by default. Currently the only available alternative is lz4. You can set that per column. Any time.

            LZ4 (lz4) is considerably faster, while compressing typically a bit less. About twice as fast, but around 10 % more storage (depends!). If performance is not an issue it's best to stick to the stronger compression of the default LZ algorithm (pglz). There may be more compression algorithms to pick from in the future.

            To implement:



            More elegant way of validate body in go-gin
            Asked 2022-Mar-19 at 21:55
            Is there a more elegant way to validate json body and route id using go-gin? ...


            Answered 2022-Mar-19 at 21:55

            Using middlewares is certainly not the way to go here, your hunch is correct! Using FastAPI as inspiration, I usually create models for every request/response that I have. You can then bind these models as query, path, or body models. An example of query model binding (just to show you that you can use this to more than just json post requests):



            Is it possible to update the log level of a zap logger at runtime?
            Asked 2022-Mar-17 at 18:11

            I created a logger with kubebuilder, it is based on zap logger:



            Answered 2022-Mar-17 at 18:11

            Better answer: as suggested by @Oliver Dain, use zap.AtomicLevel. See their answer for details.

            Another option is to create a core with a custom LevelEnabler function. You can use zap.LevelEnablerFunc to convert a closure to a zapcore.LevelEnabler.

            The relevant docs:

            LevelEnabler decides whether a given logging level is enabled when logging a message.

            LevelEnablerFunc is a convenient way to implement zapcore.LevelEnabler with an anonymous function.

            That function may then return true or false based on some other variable that changes at runtime:



            What is the use of test mode in Gin
            Asked 2022-Mar-16 at 15:27

            I've checked the documentation but it does not explain the use of setting test mode for gin



            Answered 2022-Mar-16 at 14:50

            The flag gin.DebugMode is used to control the output of gin.IsDebugging(), which adds some additional log output and changes the HTML renderer to the debug struct HTMLDebug.

            The gin.TestMode is used in Gin's own unit tests to toggle the debug mode (and the additional logging) on and off, and the usage of the debug HTML renderer.

            Other than that, it doesn't have other uses (source).

            However, the flag can be controlled with the environment variable GIN_MODE=test. Then, since Mode() is exported, you can use it in application code to, for example, declare testing routes. This might have some merit if you plan to run an E2E test suite, or some other integration test:



            Can't load html file with LoadHTMLGlob in production build. It's working in development
            Asked 2022-Mar-15 at 11:00

            I'm using the Go Gin package in my rest-API service. To add some data I used HTML file to submit the form with data. In development, it's working, but in the production build server not working, if I commented 'LoadHTMLGlob' block server working again. I think 'LoadHTMLGlob' can't load HTML. Please help to solve this issue.

            my main.go file:



            Answered 2022-Mar-15 at 11:00

            You need to add WorkingDirectory to your system file



            outline scatterplot/barplot with line graph with categorical data and groups in ggplot
            Asked 2022-Mar-05 at 14:03

            I have a dataset with ~ 150 countries, a grouping variable, and a value for each country and group (0-6). I am trying to show, that countries with a higher GDP get higher values in one group than the other. I made a scatterplot showing the values for each country by group (the countries are sorted by GDP). I want to draw a line around the points, so it becomes more aparent which group has higher values in which range of GDP. I am however, at a loss.



            Answered 2022-Mar-05 at 14:03

            Here's one idea to help visualize the difference you are trying to show. Firstly, the country names on the x axis are likely to remain illegible however you try to label them. It might therefore be better to have the rank of the countries on the x axis.

            Drawing a polygon around the points might make the point visually, but doesn't make much sense in statistical terms. What might be better here is to plot a regression with a separate line for each group. Since we are dealing with count data, we can use Poisson regression, and since we have a numeric rank on the x axis, it is possible to have lines going across your plot to show the regression.



            golang: serving net.Conn using a gin router
            Asked 2022-Feb-22 at 21:13

            I have a function that handles an incoming TCP connection:



            Answered 2022-Feb-16 at 22:34

            Create a net.Listener implementation that accepts connections by receiving on a channel:



            Postgres choosing a query plan that is more expensive by its own estimates
            Asked 2022-Feb-17 at 17:25

            I have the following 2 query plans for a particular query (second one was obtained by turning seqscan off):

            The cost estimate for the second plan is lower than that for the first, however, pg only chooses the second plan if forced to do so (by turning seqscan off).

            What could be causing this behaviour?

            EDIT: Updating the question with information requested in a comment:

            Output for EXPLAIN (ANALYZE, BUFFERS, VERBOSE) for query 1 (seqscan on; does not use index). Also viewable at



            Answered 2022-Feb-17 at 11:43

            You should have those two indexes to speed up your query :



            How to preserve path params after handling a request with router.Any and wildcard
            Asked 2022-Feb-17 at 13:31

            In my case need to catch request and check is internal request or not. If not, redirect these request to other handler function.

            URL example:



            Answered 2022-Feb-17 at 13:31

            Use a sub-engine.

            You can instantiate an engine with gin.New for internal routes only and not run it. Instead you pass the context from your Any route to Engine.HandleContext.

            This will relay the context from the main engine, and it will match path params based on the placeholders in the sub-routes.

            You can declare routes on the sub-engine as usual:


            Community Discussions, Code Snippets contain sources that include Stack Exchange Network


            No vulnerabilities reported

            Install gin

            To install Gin package, you need to install Go and set your Go workspace first.
            The first need Go installed (version 1.13+ is required), then you can use the below Go command to install Gin.
            Import it in your code:
            (Optional) Import net/http. This is required for example if using constants such as http.StatusOK.
            Gin uses encoding/json as default json package but you can change it by build from other tags.
            Gin enables MsgPack rendering feature by default. But you can disable this feature by specifying nomsgpack build tag. This is useful to reduce the binary size of executable files. See the detail information.
            You can build a server into a single binary containing templates by using go-assets. See a complete example in the directory.


            example for 1-line LetsEncrypt HTTPS servers. example for custom autocert manager.
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
          • HTTPS


          • CLI

            gh repo clone gin-gonic/gin

          • sshUrl


          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link