Coder Social home page Coder Social logo

xesina / golang-echo-realworld-example-app Goto Github PK

View Code? Open in Web Editor NEW

This project forked from gothinkster/realworld-starter-kit

491.0 491.0 127.0 206 KB

Exemplary real world backend API built with Golang + Echo

Home Page: https://realworld.io

License: MIT License

Go 97.51% Makefile 0.89% Dockerfile 1.60%
echo go golang realworld-backend

golang-echo-realworld-example-app's Introduction

Hi there ๐Ÿ‘‹

golang-echo-realworld-example-app's People

Contributors

1995parham avatar alonski avatar ericsimons avatar esakkiraj avatar olehcambel avatar optikfluffel avatar xesina avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

golang-echo-realworld-example-app's Issues

Bug: Database is locked on article create

Steps to reproduce:

  1. create article (POST /article) with title = "string"
  2. try the same request . You will get an error
    {
        "errors": {
            "body": "UNIQUE constraint failed: articles.slug"
        }
    }
  3. As transaction has started and not rollback or commit, when you run the same request, you will get
    {
        "errors": {
            "body": "database is locked"
        }
    }

Solution is to add tx.Rollback() before returning error in create
https://github.com/xesina/golang-echo-realworld-example-app/blob/master/store/article.go#L44-L47
https://github.com/xesina/golang-echo-realworld-example-app/blob/master/store/article.go#L71

Access to store from middleware

Thank you very much for your example, I am following the design pattern, but I am facing a problem, I implemented a function to check data in the db in a middleware, but I do not know how to access the store from the router / middleware route, could you give me an example of how to do this?

Here is my example code:

public, err := publicKey(c)
			if err != nil {
				return c.JSON(http.StatusUnauthorized, utils.NewError(err))
			}
			secret, err := secretKey(c)
			if err != nil {
				return c.JSON(http.StatusUnauthorized, utils.NewError(err))
			}
			company := model.Company{
				Keys: model.Keys{
					Public: public,
					Secret: secret,
				},
			}
			resp, err := store.CompanyStore{}.GetByKeys(&company)
			if err != nil {
				return c.JSON(http.StatusForbidden, utils.NewError(ErrKeysInvalid))
			}
			c.Set("company", resp)
			return next(c)

add tests

the testing part is really important I think. You should add it.

fatal error: unexpected signal during runtime execution

Hi,

Thank you for your work on this repo. Currently I'm running into the following problem when installing and running this project. Is there a missing package in this go.mod?

I'm using golang 1.17. and I'm getting the following error when running go run main.go

fatal error: unexpected signal during runtime execution
[signal SIGSEGV: segmentation violation code=0x1 addr=0xb01dfacedebac1e pc=0x7fff6dd2f70a]

runtime stack:
runtime: unexpected return pc for runtime.sigpanic called from 0x7fff6dd2f70a
stack: frame={sp:0x7ffeefbff1b8, fp:0x7ffeefbff208} stack=[0x7ffeefb80258,0x7ffeefbff2c0)
0x00007ffeefbff0b8:  0x01007ffeefbff0d8  0x0000000000000004 
0x00007ffeefbff0c8:  0x000000000000001f  0x00007fff6dd2f70a 
0x00007ffeefbff0d8:  0x0b01dfacedebac1e  0x0000000000000001 
0x00007ffeefbff0e8:  0x0000000004034251 <runtime.throw+0x0000000000000071>  0x00007ffeefbff188 
0x00007ffeefbff0f8:  0x0000000004754b93  0x00007ffeefbff140 
0x00007ffeefbff108:  0x0000000004034508 <runtime.fatalthrow.func1+0x0000000000000048>  0x00000000054f46c0 
0x00007ffeefbff118:  0x0000000000000001  0x0000000000000001 
0x00007ffeefbff128:  0x00007ffeefbff188  0x0000000004034251 <runtime.throw+0x0000000000000071> 
0x00007ffeefbff138:  0x00000000054f46c0  0x00007ffeefbff178 
0x00007ffeefbff148:  0x0000000004034490 <runtime.fatalthrow+0x0000000000000050>  0x00007ffeefbff158 
0x00007ffeefbff158:  0x00000000040344c0 <runtime.fatalthrow.func1+0x0000000000000000>  0x00000000054f46c0 
0x00007ffeefbff168:  0x0000000004034251 <runtime.throw+0x0000000000000071>  0x00007ffeefbff188 
0x00007ffeefbff178:  0x00007ffeefbff1a8  0x0000000004034251 <runtime.throw+0x0000000000000071> 
0x00007ffeefbff188:  0x00007ffeefbff190  0x0000000004034280 <runtime.throw.func1+0x0000000000000000> 
0x00007ffeefbff198:  0x000000000475cf60  0x000000000000002a 
0x00007ffeefbff1a8:  0x00007ffeefbff1f8  0x0000000004049856 <runtime.sigpanic+0x0000000000000396> 
0x00007ffeefbff1b8: <0x000000000475cf60  0x00000000054f46c0 
0x00007ffeefbff1c8:  0x00007ffeefbff238  0x0000000004027206 <runtime.(*mheap).allocSpan+0x0000000000000546> 
0x00007ffeefbff1d8:  0x000000c000206000  0x000000000000e000 
0x00007ffeefbff1e8:  0x00007fff00000008  0x0000000000000000 
0x00007ffeefbff1f8:  0x00007ffeefbff240 !0x00007fff6dd2f70a 
0x00007ffeefbff208: >0x00007ffeefbff240  0x0000000004b8b000 
0x00007ffeefbff218:  0x00000000000004f3  0x0000000004372585 <golang.org/x/sys/unix.libc_ioctl_trampoline+0x0000000000000005> 
0x00007ffeefbff228:  0x0000000004065e5f <runtime.syscall+0x000000000000001f>  0x000000c000127968 
0x00007ffeefbff238:  0x00000000040657cc <runtime.nanotime_trampoline+0x000000000000000c>  0x000000c000127938 
0x00007ffeefbff248:  0x0000000004063cf0 <runtime.asmcgocall+0x0000000000000070>  0x0000000000000007 
0x00007ffeefbff258:  0x0000000004007a00 <runtime.(*cpuProfile).add+0x0000000000000100>  0x7a00000000001018 
0x00007ffeefbff268:  0x0000000000000010  0x00000000056a8bf8 
0x00007ffeefbff278:  0x00000000000006f0  0x000000c0000001a0 
0x00007ffeefbff288:  0x0000000004061e09 <runtime.systemstack+0x0000000000000049>  0x0000000000000004 
0x00007ffeefbff298:  0x0000000004831ac8  0x00000000054f46c0 
0x00007ffeefbff2a8:  0x00007ffeefbff2f0  0x0000000004061d05 <runtime.mstart+0x0000000000000005> 
0x00007ffeefbff2b8:  0x0000000004061cbd <runtime.rt0_go+0x000000000000013d> 
runtime.throw({0x475cf60, 0x54f46c0})
        /usr/local/go/src/runtime/panic.go:1198 +0x71
runtime: unexpected return pc for runtime.sigpanic called from 0x7fff6dd2f70a
stack: frame={sp:0x7ffeefbff1b8, fp:0x7ffeefbff208} stack=[0x7ffeefb80258,0x7ffeefbff2c0)
0x00007ffeefbff0b8:  0x01007ffeefbff0d8  0x0000000000000004 
0x00007ffeefbff0c8:  0x000000000000001f  0x00007fff6dd2f70a 
0x00007ffeefbff0d8:  0x0b01dfacedebac1e  0x0000000000000001 
0x00007ffeefbff0e8:  0x0000000004034251 <runtime.throw+0x0000000000000071>  0x00007ffeefbff188 
0x00007ffeefbff0f8:  0x0000000004754b93  0x00007ffeefbff140 
0x00007ffeefbff108:  0x0000000004034508 <runtime.fatalthrow.func1+0x0000000000000048>  0x00000000054f46c0 
0x00007ffeefbff118:  0x0000000000000001  0x0000000000000001 
0x00007ffeefbff128:  0x00007ffeefbff188  0x0000000004034251 <runtime.throw+0x0000000000000071> 
0x00007ffeefbff138:  0x00000000054f46c0  0x00007ffeefbff178 
0x00007ffeefbff148:  0x0000000004034490 <runtime.fatalthrow+0x0000000000000050>  0x00007ffeefbff158 
0x00007ffeefbff158:  0x00000000040344c0 <runtime.fatalthrow.func1+0x0000000000000000>  0x00000000054f46c0 
0x00007ffeefbff168:  0x0000000004034251 <runtime.throw+0x0000000000000071>  0x00007ffeefbff188 
0x00007ffeefbff178:  0x00007ffeefbff1a8  0x0000000004034251 <runtime.throw+0x0000000000000071> 
0x00007ffeefbff188:  0x00007ffeefbff190  0x0000000004034280 <runtime.throw.func1+0x0000000000000000> 
0x00007ffeefbff198:  0x000000000475cf60  0x000000000000002a 
0x00007ffeefbff1a8:  0x00007ffeefbff1f8  0x0000000004049856 <runtime.sigpanic+0x0000000000000396> 
0x00007ffeefbff1b8: <0x000000000475cf60  0x00000000054f46c0 
0x00007ffeefbff1c8:  0x00007ffeefbff238  0x0000000004027206 <runtime.(*mheap).allocSpan+0x0000000000000546> 
0x00007ffeefbff1d8:  0x000000c000206000  0x000000000000e000 
0x00007ffeefbff1e8:  0x00007fff00000008  0x0000000000000000 
0x00007ffeefbff1f8:  0x00007ffeefbff240 !0x00007fff6dd2f70a 
0x00007ffeefbff208: >0x00007ffeefbff240  0x0000000004b8b000 
0x00007ffeefbff218:  0x00000000000004f3  0x0000000004372585 <golang.org/x/sys/unix.libc_ioctl_trampoline+0x0000000000000005> 
0x00007ffeefbff228:  0x0000000004065e5f <runtime.syscall+0x000000000000001f>  0x000000c000127968 
0x00007ffeefbff238:  0x00000000040657cc <runtime.nanotime_trampoline+0x000000000000000c>  0x000000c000127938 
0x00007ffeefbff248:  0x0000000004063cf0 <runtime.asmcgocall+0x0000000000000070>  0x0000000000000007 
0x00007ffeefbff258:  0x0000000004007a00 <runtime.(*cpuProfile).add+0x0000000000000100>  0x7a00000000001018 
0x00007ffeefbff268:  0x0000000000000010  0x00000000056a8bf8 
0x00007ffeefbff278:  0x00000000000006f0  0x000000c0000001a0 
0x00007ffeefbff288:  0x0000000004061e09 <runtime.systemstack+0x0000000000000049>  0x0000000000000004 
0x00007ffeefbff298:  0x0000000004831ac8  0x00000000054f46c0 
0x00007ffeefbff2a8:  0x00007ffeefbff2f0  0x0000000004061d05 <runtime.mstart+0x0000000000000005> 
0x00007ffeefbff2b8:  0x0000000004061cbd <runtime.rt0_go+0x000000000000013d> 
runtime.sigpanic()
        /usr/local/go/src/runtime/signal_unix.go:719 +0x396

goroutine 1 [syscall, locked to thread]:
syscall.syscall(0x4372580, 0x1, 0x40487413, 0xc0001279f8)
        /usr/local/go/src/runtime/sys_darwin.go:22 +0x3b fp=0xc000127968 sp=0xc000127948 pc=0x406093b
syscall.syscall(0xc0001f2506, 0xc000127a38, 0x400ddd4, 0x100000000000000)
        <autogenerated>:1 +0x26 fp=0xc0001279b0 sp=0xc000127968 pc=0x4066626
golang.org/x/sys/unix.ioctl(0x18, 0x100000005900108, 0x5909328)
        /Users/XXXXX/go/pkg/mod/golang.org/x/[email protected]/unix/zsyscall_darwin_amd64.go:746 +0x39 fp=0xc0001279e0 sp=0xc0001279b0 pc=0x4372219
golang.org/x/sys/unix.IoctlGetTermios(...)
        /Users/XXXXX/go/pkg/mod/golang.org/x/[email protected]/unix/ioctl.go:63
github.com/mattn/go-isatty.IsTerminal(0x46d5040)
        /Users/XXXXX/go/pkg/mod/github.com/mattn/[email protected]/isatty_bsd.go:10 +0x50 fp=0xc000127a50 sp=0xc0001279e0 pc=0x4372630
github.com/labstack/gommon/color.(*Color).SetOutput(0xc00000ed38, {0x48393a0, 0xc000010018})
        /Users/XXXXX/go/pkg/mod/github.com/labstack/[email protected]/color/color.go:146 +0x92 fp=0xc000127a70 sp=0xc000127a50 pc=0x4372a72
github.com/labstack/gommon/color.New(...)
        /Users/XXXXX/go/pkg/mod/github.com/labstack/[email protected]/color/color.go:134
github.com/labstack/gommon/color.init()
        /Users/XXXXX/go/pkg/mod/github.com/labstack/[email protected]/color/color.go:102 +0x4ea fp=0xc000127aa0 sp=0xc000127a70 pc=0x437412a
runtime.doInit(0x4b93a60)
        /usr/local/go/src/runtime/proc.go:6498 +0x123 fp=0xc000127bd8 sp=0xc000127aa0 pc=0x40437c3
runtime.doInit(0x4b98ea0)
        /usr/local/go/src/runtime/proc.go:6475 +0x71 fp=0xc000127d10 sp=0xc000127bd8 pc=0x4043711
runtime.doInit(0x4b94f20)
        /usr/local/go/src/runtime/proc.go:6475 +0x71 fp=0xc000127e48 sp=0xc000127d10 pc=0x4043711
runtime.doInit(0x4b92fe0)
        /usr/local/go/src/runtime/proc.go:6475 +0x71 fp=0xc000127f80 sp=0xc000127e48 pc=0x4043711
runtime.main()
        /usr/local/go/src/runtime/proc.go:238 +0x1e6 fp=0xc000127fe0 sp=0xc000127f80 pc=0x40368a6
runtime.goexit()
        /usr/local/go/src/runtime/asm_amd64.s:1581 +0x1 fp=0xc000127fe8 sp=0xc000127fe0 pc=0x4063fe1
exit status 2

Access to store from middleware

Thank you very much for your example, I am following the design pattern, but I am facing a problem, I implemented a function to check data in the db in a middleware, but I do not know how to access the store from the router / middleware route, could you give me an example of how to do this?

Here is my example code:

public, err := publicKey(c)
			if err != nil {
				return c.JSON(http.StatusUnauthorized, utils.NewError(err))
			}
			secret, err := secretKey(c)
			if err != nil {
				return c.JSON(http.StatusUnauthorized, utils.NewError(err))
			}
			company := model.Company{
				Keys: model.Keys{
					Public: public,
					Secret: secret,
				},
			}
			resp, err := store.CompanyStore{}.GetByKeys(&company)
			if err != nil {
				return c.JSON(http.StatusForbidden, utils.NewError(ErrKeysInvalid))
			}
			c.Set("company", resp)
			return next(c)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.