V
V
Vladimir Grabko2016-05-05 20:52:24
go
Vladimir Grabko, 2016-05-05 20:52:24

How to pass a struct to another package?

Let's say I have db.Add(u) where u is of type User. In this function (db.Add), I want to save the structure in the map in order to use it later in this package (create a map with this type). I assume that it is possible to do this (the same gorm uses something similar). I'm just trying to implement a relational database in RAM (without sql, etc. immediately orm that stores everything in RAM for the cache will be the most)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
fastpars, 2016-05-05
@fastpars

myPackage.go

package myPackage

type User struct {
  ID string
}

func AddUser(user User) {
  // ...
}

package main

import "myPackage"

func main() {
  myPackage.AddUser(myPackage.User{
    ID: "...",
  })
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question