Git Product home page Git Product logo

Comments (10)

SerkanSipahi avatar SerkanSipahi commented on July 23, 2024 1

my quote:

please show me a way :)

this is a way "for me" how to handle features thats not implemented in kivik ! thank you very much :)

from kivik.

flimzy avatar flimzy commented on July 23, 2024

Kivik does not currently support user manipulation (adding, updating, or deleting users). I have always handled this through the management interface (Fauxton, etc). But it's probably a good idea to add support to Kivik, too.

from kivik.

SerkanSipahi avatar SerkanSipahi commented on July 23, 2024

@flimzy How do you handle features they are not supported in kivik? maybe like this? in very plain style?

type User struct {
	Name     string        `json:"name"`
	Password string        `json:"password"`
	Roles    []interface{} `json:"roles"`
	Type     string        `json:"type"`
}

data := User{
	// fill struct
}
userBytes, err := json.Marshal(data)
if err != nil {
	// handle err
}
body := bytes.NewReader(userBytes)

req, err := http.NewRequest("PUT", "http://localhost:5984/_users/org.couchdb.user"+data.Name, body)
if err != nil {
	// handle err
}
req.Header.Set("Accept", "application/json")
req.Header.Set("Content-Type", "application/json")

resp, err := http.DefaultClient.Do(req)
if err != nil {
	// handle err
}
defer resp.Body.Close()

from kivik.

flimzy avatar flimzy commented on July 23, 2024

Yes, that's a reasonable approach as a stop-gap, until I have time to add user management to Kivik. :) I'll try to get around to adding that soon, but it may be a week or two before I have time.

from kivik.

SerkanSipahi avatar SerkanSipahi commented on July 23, 2024

@flimzy ok thank you. Let me know when it implemented :)

from kivik.

flimzy avatar flimzy commented on July 23, 2024

Please forgive my hasty response earlier; adding a standard user is quite possible with Kivik, as users are stored as standard documents. It is creation of admin users which is not currently possible.

For your use case, just do something like this:

	client, _ := kivik.New(context.TODO(), "couch", "http://localhost:5984/")
	usersDB, _ := client.DB(context.TODO(), "_users")
	user := map[string]interface{}{
		"_id":      kivik.UserPrefix + "username",
		"type":     "user",
		"password": "abc123",
	}
	_, _ = usersDB.Put(context.TODO(), kivik.UserPrefix+"username", user)

from kivik.

flimzy avatar flimzy commented on July 23, 2024

Sorry it took me a while to catch up... I guess I was sleeping when I responded yesterday. :)

I'll add this example to the wiki before I close this issue.

from kivik.

SerkanSipahi avatar SerkanSipahi commented on July 23, 2024

Sorry it took me a while to catch up... I guess I was sleeping when I responded yesterday. :)

lol

I'll add this example to the wiki before I close this issue.

I think this will help many developers. Your example is very useful for many cases. Its reduce my example to few lines of code :)

from kivik.

flimzy avatar flimzy commented on July 23, 2024

The wiki is now updated.

from kivik.

SerkanSipahi avatar SerkanSipahi commented on July 23, 2024

thanks.

from kivik.

Related Issues (20)

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.