#Hello World Question

1 messages · Page 1 of 1 (latest)

keen pier
#

Ok - been getting a handle on Go and Dagger over the weekend. Here's the one thing I can't seem to understand. If I'm following the guide here for your first module - I get it to work as designed. https://docs.dagger.io/manuals/developer/go/525021/first-module
Here's the question - how does the function in the demo:
func (m *Potato) HelloWorld() string {
return "Hello Daggernauts!"
}
equate to "dagger call hello-world" vs "dagger call helloworld" I don't see anywhere that it's defined as such and trying other commands like "dagger call helloworld" fail

I saw the note in the docs around "kebab-style" - but how/why does hello-world work? I know this is something simple - but I can't find anything on it in the docs. Asking as I'm obviously confused, but this of course will determine function naming I assume as I move forward.

I looked here: https://go.dev/ref/spec#Function_declarations

saw this - but still don't see how it went from HelloWorld() to hello-world - PLEASE enlighten me 🙂 TIA for the help!

A defined type may have methods associated with it. It does not inherit any methods bound to the given type, but the method set of an interface type or of elements of a composite type remains unchanged:

// A Mutex is a data type with two methods, Lock and Unlock.
type Mutex struct { /* Mutex fields */ }
func (m Mutex) Lock() { / Lock implementation */ }
func (m Mutex) Unlock() { / Unlock implementation */ }

// NewMutex has the same composition as Mutex but its method set is empty.
type NewMutex Mutex

// The method set of PtrMutex's underlying type *Mutex remains unchanged,
// but the method set of PtrMutex is empty.
type PtrMutex *Mutex

// The method set of *PrintableMutex contains the methods
// Lock and Unlock bound to its embedded field Mutex.
type PrintableMutex struct {
Mutex
}

// MyBlock is an interface type that has the same method set as Block.
type MyBlock Block

#

ok - is it the fact that HelloWorld function name has a capital 'W' and as a result Dagger splits at the W for the kebab-style naming? Based on the docs from:https://docs.dagger.io/manuals/developer/go/264203/functions It's the only way I can see it working.

Dagger Functions are regular code, written in a supported programming language, and running in containers. Dagger Functions let you encapsulate common operations or workflows into discrete units with clear inputs and outputs.

#

yup - I think I answered my own question - some quick testing shows that to be the case - if I'm wrong - lmk. Thanks!

prime lantern
#

You got it right 🙂

#

Sorry for the confusion