livebud / bud

The Full-Stack Web Framework for Go
MIT License
5.58k stars 179 forks source link

Too many return values error on loadController() #101

Closed joesamcoke closed 2 years ago

joesamcoke commented 2 years ago

Hi, Firstly this project looks great. Really looking forward to working with it.

Getting the error...

bud/.app/controller/controller.go:133:15: too many return values have (nil, error)

Looks the loadController() is missing a return error definination

func loadController() *controller.Controller { controllerController, err := controller.Load() if err != nil { return nil, err } return controllerController }

matthewmueller commented 2 years ago

Hey @joesamcoke, thanks for giving bud a try!

Can you share what you wrote in your controller/ directory? I just need the signature if the body is private.

joesamcoke commented 2 years ago

Sorry, I was adding a basic controller dependancy on the main controller.

package controller

import (
    context "context"

    "gorm.io/driver/sqlite"
    "gorm.io/gorm"
)

func Load() (*Controller, error) {
    db, err := gorm.Open(sqlite.Open("test.db"), &gorm.Config{})
    if err != nil {
        return nil, err
    }
    return &Controller{db}, nil
}

type Controller struct {
    db *gorm.DB
}

As per what you have in the docs...

package users

func Load(log log.Logger, env *env.Env) (*Controller, error) {
  db, err := pgx.Connect(env.PostgresURL)
  if err != nil {
    return nil, err
  }
  return &Controller{log, db}
}

type Controller struct {
  log log.Log
  db  *pgx.Client
}

It maybe just an issue with the code in the docs as it doesn't seem possible to return an error from the Load() function.

matthewmueller commented 2 years ago

Thanks @joesamcoke. Please fix formatting, I can barely read this 😅

joesamcoke commented 2 years ago

eek, ok that's done

matthewmueller commented 2 years ago

Ah interesting, let me try to reproduce this!

matthewmueller commented 2 years ago

Yep, confirmed the issue. We'll get this fixed!

This problem can be simplified to:

package controller

func Load() (*Controller, error) {
    return &Controller{}, nil
}

type Controller struct {
}

func (c *Controller) Index() string {
    return ""
}

There's a problem somewhere in the controller generator

Pubg887 commented 2 years ago

Jj

matthewmueller commented 2 years ago

@Pubg887 Accident?